生活随笔
收集整理的這篇文章主要介紹了
(三)基于PHP——复杂的WSDL的创建(WSDL篇)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
(三)基于PHP——復雜的WSDL的創建(WSDL篇)
標簽:?phpsoapbindingschemaextensionoutput 2011-11-10 15:05?
1562人閱讀??
收藏?
舉報
?
分類: ? WSDL(2)?
版權聲明:本文為博主原創文章,未經博主允許不得轉載。
轉載請注明出處:http://blog.csdn.net/cwt0408/article/details/6952936
(謝謝合作!)
調用數組內容:
1、修改service.php
[html]?view plain
?copy <?php?? class?PhoneBookInfo{?? ????public?$name,$number,$relationship,$email;?? ????public?function?__construct($pname,$pnumber,$prelationship,$pemail){?? ????????$this->name=$pname;?? ????????$this->number=$pnumber;?? ????????$this->relationship=$prelationship;?? ????????$this->email=$pemail;?? ????}????? }?? /*可以在這里調用數據庫,下面是測試數據*/?? function?GetPhoneBook($inname)?? {?? ????$pinfo=array();?? ????$pinfo[]=new?PhoneBookInfo(?? ????????'zhangsan',?? ????????'13333333333',?? ????????'friend',?? ????????'3333@163.com'?? ????);?? ?????? ????$pinfo[]=new?PhoneBookInfo(?? ??????'lisi',?? ??????'13444444444',?? ??????'friend',?? ??????'4444@163.com'?? ?????);?? ???? ??$pinfo[]=new?PhoneBookInfo(?? ??????'wangwu',?? ??????'135555555555',?? ??????'friend',?? ??????'5555@163.com'?? ?????);????? ????return?$pinfo;?? }?? ?? $server?=?new?SoapServer("myphone.wsdl");?? $server->addFunction("GetPhoneBook");?? $server->handle?();??? ?>?? 2、client.php
[html]?view plain
?copy <?php?? header('Content-Type:text/html;charset=utf-8');?? $client?=?new?SoapClient("http://www.mysoapservice.cn/service.php?WSDL"?,?array('trace'=>true));?? var_dump($client->__getTypes());?? try?{?? ?$response?=?$client->GetPhoneBook('zhang');?? ?var_dump($response);?? }catch?(SoapFault?$sf){?? ?var_dump($sf);?? ?print?($client->__getLastRequest());?? ?print?($client->__getLastResponse());?? }?? ?>?? 3、關鍵修改myphone.wsdl
[html]?view plain
?copy <?xml?version?='1.0'?encoding?='UTF-8'??>??? <definitions?name='phonebook'??? ??targetNamespace='http://www.mysoapservice.cn/'??? ??xmlns:tns='http://www.mysoapservice.cn/'?? ??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>?? ????<xsd:schema?xmlns:xsd="http://www.w3.org/2001/XMLSchema"??? ????????targetNamespace="http://www.mysoapservice.cn/"?? ????????xmlns:Q1="soapenc">??? ????????<xsd:complexType?name="PhoneBookInfoArray">?? ????????????<xsd:complexContent>?? ????????????????<xsd:restriction?base="soapenc:Array">?? ????????????????????<xsd:attribute?ref="sopenc:arrayType"?wsdl:arrayType="tns:PhoneBookInfo[]"/>?? ????????????????</xsd:restriction>?? ????????????</xsd:complexContent>??? ????????</xsd:complexType>?? ?????????? ????????<xsd:complexType?name="PhoneBookInfo">?? ????????????<xsd:all>?? ????????????????<xsd:element?name="name"?type="xsd:string"></xsd:element>?? ????????????????<xsd:element?name="number"?type="xsd:string"></xsd:element>?? ????????????????<xsd:element?name="relationship"?type="xsd:string"></xsd:element>?? ????????????????<xsd:element?name="email"?type="xsd:string"></xsd:element>?? ????????????</xsd:all>?? ????????</xsd:complexType>?? ????</xsd:schema>?? ?</types>??? ?? <message?name='GetPhoneBookRequest'>??? ????<part?name="inname"?type="xsd:string"/>?? </message>??? ?? <message?name='GetPhoneBookResponse'>??? ????<part?name="phonebookInfo"?type="xsd:PhoneBookInfoArray"/>?? </message>?? ?? <portType?name='PhoneBookToEveryOneProt'>??? ??<operation?name='GetPhoneBook'>??? ????<input?message='tns:GetPhoneBookRequest'/>??? ????<output?message='tns:GetPhoneBookResponse'/>??? ??</operation>?? </portType>?? ?? <binding?name='PhoneBookSOAP'?type='tns:PhoneBookToEveryOneProt'>??? ??<soap:binding?style='rpc'??? ????transport='http://schemas.xmlsoap.org/soap/http'/>??? ??<operation?name='GetPhoneBook'>??? ????<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?name='PhoneBookService'>??? ??<port?name='PhoneBookSOAP'?binding='tns:PhoneBookSOAP'>??? ????<soap:address?location='http://www.mysoapservice.cn/service.php'/>??? ??</port>??? </service>??? </definitions>?? 對比修改地方:
測試結果:
另外需要注意的地方:
如果遇到I/O錯誤:
1、在php.ini中打開extension=php_curl.dll
2、copy:?libeay32.dll、ssleay32.dll到system32下
這兩個dll網上都有下載!我就不傳了!
總結
以上是生活随笔為你收集整理的(三)基于PHP——复杂的WSDL的创建(WSDL篇)的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。