修改调用客户端。也就是说修改PHP.ini,修改一下配置,改完之后重启Apache服务器。
二、WSDL(文件说明)
我们调用一下该服务的地址:http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?WSDL
<?PHP //客户端通过wsdl,即可以了解webservice的可调用方法及参数的细节 $soapclient=new soapclient('http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?WSDL'); print_r($soapclient->__getFunctions()); ?>
结果:
<?PHP //客户端通过wsdl,即可以了解webservice的可调用方法及参数的细节 $soapclient=new soapclient('http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?WSDL'); //print_r($soapclient->__getFunctions());//分析webservice有哪些方法调用 print_r($soapclient->getMobileCodeInfo(array('mobileCode'=>13121859603))); ?>
三、构造自己的webservice服务器
1.新建wsdl.xml
<?xml version='1.0' encoding='UTF-8'?> <deFinitions name='zixue.it' targetNamespace='http://localhost/webservice/' xmlns:tns='http://localhost/webservice/' xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/' xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/' xmlns='http://schemas.xmlsoap.org/wsdl/'> <!--<types>元素定义webservice 使用的数据类型,WSDL使用XML Schema 语法来定义数据类型,也可以自定义Schema不包含的类型 --> <types> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://localhost/webservice/"> </xsd:schema> </types> <!--<message>元素可以定义每个消息的部件,以及相关的数据类型--> <message name='sumRequest'> <part name="term" type="xsd:string"/> </message> <message name='sumResponse'> <part name="value" type="xsd:string"/> </message> <!--<portType>元素是最重要的WSDL元素。它可描述一个web service、可被执行的操作,以及相关的消息。他告诉你去哪个webservice的连接点,扮演了一个控制者--> <portType name='oplist'> <operation name='sum'> <input message='tns:sumRequest'/> <output message='tns:sumResponse'/> </operation> </portType> <!--<binding>元素为每个端口定义消息格式和协议细节--> <binding name='cartSoap' type='tns:oplist'> <!--style:属性可取值"rpc"或"document",ransport:属性定义了要使用的SOAP协议.在这个例子中我们使用HTTP--> <soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http'/> <!--operation元素定义了每个端口提供的操作符,相应的SOAP行为都需要被定义--> <operation name='sum'> <soap:operation soapAction='http://www.cwtservice.cn/newOperation/'/> <input> <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes' encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> </input> <output> <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes' encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> </output> </operation> </binding> <!--<service>包含一个或多个port元素,每个port元素表示一个不同的web服务--> <service name='shopWS'> <port name='cartSoap' binding='tns:cartSoap'> <soap:address location='http://localhost/webservice/server.PHP'/> </port> </service> </deFinitions> <!----> <!--style:-->
新建server.PHP <?PHP function sum($str){ return 'webservice'.$str; } $server=new soapserver('./wsdl.xml');//按照wsdl的说明来创建服务器 $server->addFunction('sum'); $server->handle(); ?>
新建客户端client.PHP
<?PHP $soapclient=new soapclient('http://localhost/webservice/wsdl.xml'); //print_r($soapclient->__getFunctions()); ?>
打印出来:
Array
(
[0] => string sum(string $term)
)
在client.PHP中加入以下内容:/** 这说明,可以调用服务端的sum方法,并传字符串参数叫term,且返回字符串参数 * */ echo $soapclient->sum('haha');显示:
我们传的参数是字符串类型,我们想传一个数组的参数该怎么办呢?
预览client.PHP
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。