(三)基于PHP——复杂的WSDL的创建(WSDL篇)

本文详细介绍了如何使用PHP创建复杂WSDL的过程,包括修改service.php文件、配置客户端及关键调整myphone.wsdl文件的步骤。通过实例演示了如何实现服务调用并处理返回的数据。
 

(三)基于PHP——复杂的WSDL的创建(WSDL篇)

标签: phpsoapbindingschemaextensionoutput
  1562人阅读  评论(0)  收藏  举报
  分类:
 

转载请注明出处:http://blog.youkuaiyun.com/cwt0408/article/details/6952936
(谢谢合作!)

调用数组内容:
1、修改service.php

[html]  view plain  copy
  1. <?php  
  2. class PhoneBookInfo{  
  3.     public $name,$number,$relationship,$email;  
  4.     public function __construct($pname,$pnumber,$prelationship,$pemail){  
  5.         $this->name=$pname;  
  6.         $this->number=$pnumber;  
  7.         $this->relationship=$prelationship;  
  8.         $this->email=$pemail;  
  9.     }     
  10. }  
  11. /*可以在这里调用数据库,下面是测试数据*/  
  12. function GetPhoneBook($inname)  
  13. {  
  14.     $pinfo=array();  
  15.     $pinfo[]=new PhoneBookInfo(  
  16.         'zhangsan',  
  17.         '13333333333',  
  18.         'friend',  
  19.         '3333@163.com'  
  20.     );  
  21.       
  22.     $pinfo[]=new PhoneBookInfo(  
  23.       'lisi',  
  24.       '13444444444',  
  25.       'friend',  
  26.       '4444@163.com'  
  27.      );  
  28.     
  29.   $pinfo[]=new PhoneBookInfo(  
  30.       'wangwu',  
  31.       '135555555555',  
  32.       'friend',  
  33.       '5555@163.com'  
  34.      );     
  35.     return $pinfo;  
  36. }  
  37.   
  38. $server = new SoapServer("myphone.wsdl");  
  39. $server->addFunction("GetPhoneBook");  
  40. $server->handle ();   
  41. ?>  

2、client.php
[html]  view plain  copy
  1. <?php  
  2. header('Content-Type:text/html;charset=utf-8');  
  3. $client = new SoapClient("http://www.mysoapservice.cn/service.php?WSDL" , array('trace'=>true));  
  4. var_dump($client->__getTypes());  
  5. try {  
  6.  $response = $client->GetPhoneBook('zhang');  
  7.  var_dump($response);  
  8. }catch (SoapFault $sf){  
  9.  var_dump($sf);  
  10.  print ($client->__getLastRequest());  
  11.  print ($client->__getLastResponse());  
  12. }  
  13. ?>  
3、关键修改myphone.wsdl
[html]  view plain  copy
  1. <?xml version ='1.0' encoding ='UTF-8' ?>   
  2. <definitions name='phonebook'   
  3.   targetNamespace='http://www.mysoapservice.cn/'   
  4.   xmlns:tns='http://www.mysoapservice.cn/'  
  5.   xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'   
  6.   xmlns:xsd='http://www.w3.org/2001/XMLSchema'   
  7.   xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'   
  8.   xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'   
  9.   xmlns='http://schemas.xmlsoap.org/wsdl/'>  
  10.     
  11.  <types>  
  12.     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"   
  13.         targetNamespace="http://www.mysoapservice.cn/"  
  14.         xmlns:Q1="soapenc">   
  15.         <xsd:complexType name="PhoneBookInfoArray">  
  16.             <xsd:complexContent>  
  17.                 <xsd:restriction base="soapenc:Array">  
  18.                     <xsd:attribute ref="sopenc:arrayType" wsdl:arrayType="tns:PhoneBookInfo[]"/>  
  19.                 </xsd:restriction>  
  20.             </xsd:complexContent>   
  21.         </xsd:complexType>  
  22.           
  23.         <xsd:complexType name="PhoneBookInfo">  
  24.             <xsd:all>  
  25.                 <xsd:element name="name" type="xsd:string"></xsd:element>  
  26.                 <xsd:element name="number" type="xsd:string"></xsd:element>  
  27.                 <xsd:element name="relationship" type="xsd:string"></xsd:element>  
  28.                 <xsd:element name="email" type="xsd:string"></xsd:element>  
  29.             </xsd:all>  
  30.         </xsd:complexType>  
  31.     </xsd:schema>  
  32.  </types>   
  33.   
  34. <message name='GetPhoneBookRequest'>   
  35.     <part name="inname" type="xsd:string"/>  
  36. </message>   
  37.   
  38. <message name='GetPhoneBookResponse'>   
  39.     <part name="phonebookInfo" type="xsd:PhoneBookInfoArray"/>  
  40. </message>  
  41.   
  42. <portType name='PhoneBookToEveryOneProt'>   
  43.   <operation name='GetPhoneBook'>   
  44.     <input message='tns:GetPhoneBookRequest'/>   
  45.     <output message='tns:GetPhoneBookResponse'/>   
  46.   </operation>  
  47. </portType>  
  48.   
  49. <binding name='PhoneBookSOAP' type='tns:PhoneBookToEveryOneProt'>   
  50.   <soap:binding style='rpc'   
  51.     transport='http://schemas.xmlsoap.org/soap/http'/>   
  52.   <operation name='GetPhoneBook'>   
  53.     <soap:operation soapAction='http://www.cwtservice.cn/newOperation/'/>   
  54.     <input>   
  55.       <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'   
  56.         encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>   
  57.     </input>   
  58.     <output>   
  59.       <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'   
  60.         encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>   
  61.     </output>   
  62.   </operation>   
  63. </binding>  
  64.   
  65. <service name='PhoneBookService'>   
  66.   <port name='PhoneBookSOAP' binding='tns:PhoneBookSOAP'>   
  67.     <soap:address location='http://www.mysoapservice.cn/service.php'/>   
  68.   </port>   
  69. </service>   
  70. </definitions>  
对比修改地方:

测试结果:

另外需要注意的地方:
如果遇到I/O错误:
1、在php.ini中打开extension=php_curl.dll
2、copy: libeay32.dll、ssleay32.dll到system32下
这两个dll网上都有下载!我就不传了!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值