原文地址:http://www.360doc.com/content/11/0212/16/15103_92457365.shtml#
php4时代调用webservice大部分使用的nusoap。到了php5已经有了自己的soap扩展。所以可以完全的抛弃nusoap这个许久没有更新过的东西了。 因为目前是本地开发需要。只说windows下的。 配置环境windows下找到php安装目录下的php.ini。打开后编辑。找到 extension=php_soap.dll 然后将前面的;号去掉。 然后就是写一个php文件来验证一下。 实例程序在apache的htdocs目录下创建ws.php 代码如下:
在浏览器中输入:http://localhost/ws.php后会出现
现在逐行解释一下。$client = new SoapClient( 'http://erp.test.com/SendSMS/Service.asmx?wsdl',array('trace' => true, 'exceptions' => true ));
POST /SendSMS/Service.asmx HTTP/1.1 Host: erp.test.com Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://test.com/SendSMS1" <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Header> <AuthenticationHeader xmlns="http://test.com/"> <Token>string</Token> </AuthenticationHeader> </soap:Header> <soap:Body> <SendSMS1 xmlns="http://test.com/"> <sms1> <Id>int</Id> <SjNo>string</SjNo> <UnickName>string</UnickName> <SmsContent>string</SmsContent> <Type>int</Type> <OrderIdString>string</OrderIdString> </sms1> </SendSMS1> </soap:Body> </soap:Envelope> 这里可以看到。soap的Header和Body。Header里就是Token。Body里就是具体的方法了。 SendSMS1节点是方法名。 sms1节点就是参数。 sms1节点下的就是参数的属性。 一定要按照顺序对属性进行逐个赋值。 |
PHP5 扩展SOAP 调用 webservice
最新推荐文章于 2021-03-09 23:23:51 发布