麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > PHP > 正文

PHP教程:WebService最常用的兩種方法

2020-03-24 18:52:34
字體:
來源:轉載
供稿:網友
企業級應用,主要是講PHP5對webservice的一些實現(以下的程序可以被JAVA,NET,C等正常調用)
國內用PHP寫WebService的真的很少,網上資料也沒多少,公司的項目開發過程中,經歷了不少這方面的東西,寫出來以供大家參考(謝謝老農提供的WSDL和程序文件)
客戶端代碼:
01. ?php
02.header ( Content-Type: text/html; charset=utf-8 );
03./*
04.* 指定WebService路徑并初始化一個WebService客戶端
05.*/
06.$ws = http://soap/soapCspMessage.php?wsdl
07.$client = new SoapClient ( $ws, array ('trace' = 1, 'uri' = 'http://www.zxsv.com/SoapDiscovery/' ) );
08./*
09.* 獲取SoapClient對象引用的服務所提供的所有方法
10.*/
11.echo ( SOAP服務器提供的開放函數:
12.echo (' pre
13.var_dump ( $client- __getFunctions () );
14.echo (' /pre
15.echo ( SOAP服務器提供的Type:
16.echo (' pre
17.var_dump ( $client- __getTypes () );
18.echo (' /pre
19.echo ( 執行GetGUIDNode的結果:
20.//$users = $client- GetUsers();
21.//var_dump($HelloWorld );
22.$parameters = array('uname'= 'zxsv', upassword = '123');
23.$out = $client- HelloWorld($parameters);
24.$datadb = $out- HelloWorldResponse;
25.var_dump($out);
26.? 服務端代碼:01. ?php
02.class Member
03.{
04.public $UserId;
05.public $Name;
06.public function __construct($parmas){
07.$this- UserId = $parmas[0];
08.$this- Name = $parmas[1];
09.}
10.}
11.$servidorSoap = new SoapServer('testphp.xml',array('uri' = 'http://www.TestPHP.com/','encoding'= 'utf-8','soap_version' = SOAP_1_2 ));
12.$servidorSoap- setClass(Testphp);
13.$servidorSoap- handle();
14.class Testphp {
15.public function HelloWorld($uid){
16.return array('HelloWorldResult'= mystring .$uid- {'uname'}.' and '.$uid- {'upassword'});
17.}
18.public function GetMember($uid){
19.$s=array();
20.for($i=0;$i $uid- {'uid'};$i++){
21.$s[] = amp;new Member(array($i, $uid- {'uname'}.'我測試'.$i));
22.}
23.return array('GetMemberResult'=
24.}
25.}
26.? 到這里應該都看的懂吧
下面是WSDL文件代碼:001. ?xml version= 1.0 encoding= utf-8 ?
002. wsdl:definitions xmlns:soap= http://schemas.xmlsoap.org/wsdl/soap/ xmlns:tm= http://microsoft.com/wsdl/mime/textMatching/ xmlns:soapenc= http://schemas.xmlsoap.org/soap/encoding/ xmlns:mime= http://schemas.xmlsoap.org/wsdl/mime/ xmlns:tns= http://www.TestPHP.com/ xmlns:s= http://www.w3.org/2001/XMLSchema xmlns:soap12= http://schemas.xmlsoap.org/wsdl/soap12/ xmlns:http= http://schemas.xmlsoap.org/wsdl/http/ targetNamespace= http://www.TestPHP.com/ xmlns:wsdl= http://schemas.xmlsoap.org/wsdl/
003. wsdl:types
004. s:schema elementFormDefault= qualified targetNamespace= http://www.TestPHP.com/
005. s:element name= HelloWorld
006. s:complexType
007. s:sequence
008. s:element minOccurs= 0 maxOccurs= 1 name= uname type= s:string /
009. s:element minOccurs= 0 maxOccurs= 1 name= upassword type= s:string /
010. /s:sequence
011. /s:complexType
012. /s:element
013. s:element name= HelloWorldResponse
014. s:complexType
015. s:sequence
016. s:element minOccurs= 0 maxOccurs= 1 name= HelloWorldResult type= s:string /
017. /s:sequence
018. /s:complexType
019. /s:element
020. s:element name= GetMember
021. s:complexType
022. s:sequence
023. s:element minOccurs= 1 maxOccurs= 1 name= uid type= s:int /
024. s:element minOccurs= 0 maxOccurs= 1 name= uname type= s:string /
025. /s:sequence
026. /s:complexType
027. /s:element
028. s:element name= GetMemberResponse
029. s:complexType
030. s:sequence
031. s:element minOccurs= 0 maxOccurs= 1 name= GetMemberResult type= tns:ArrayOfMember /
032. /s:sequence
033. /s:complexType
034. /s:element
035. s:complexType name= ArrayOfMember
036. s:sequence
037. s:element minOccurs= 0 maxOccurs= unbounded name= Member nillable= true type= tns:Member /
038. /s:sequence
039. /s:complexType
040. s:complexType name= Member
041. s:sequence
042. s:element minOccurs= 1 maxOccurs= 1 name= UserId type= s:int /
043. s:element minOccurs= 0 maxOccurs= 1 name= Name type= s:string /
044. /s:sequence
045. /s:complexType
046. /s:schema
047. /wsdl:types
048. wsdl:message name= HelloWorldSoapIn
049. wsdl:part name= parameters element= tns:HelloWorld /
050. /wsdl:message
051. wsdl:message name= HelloWorldSoapOut
052. wsdl:part name= parameters element= tns:HelloWorldResponse /
053. /wsdl:message
054. wsdl:message name= GetMemberSoapIn
055. wsdl:part name= parameters element= tns:GetMember /
056. /wsdl:message
057. wsdl:message name= GetMemberSoapOut
058. wsdl:part name= parameters element= tns:GetMemberResponse /
059. /wsdl:message
060. wsdl:portType name= TestPHPSoap
061. wsdl:operation name= HelloWorld
062. wsdl:input message= tns:HelloWorldSoapIn /
063. wsdl:output message= tns:HelloWorldSoapOut /
064. /wsdl:operation
065. wsdl:operation name= GetMember
066. wsdl:input message= tns:GetMemberSoapIn /
067. wsdl:output message= tns:GetMemberSoapOut /
068. /wsdl:operation
069. /wsdl:portType
070. wsdl:binding name= TestPHPSoap type= tns:TestPHPSoap
071. soap:binding transport= http://schemas.xmlsoap.org/soap/http /
072. wsdl:operation name= HelloWorld
073. soap:operation soapAction= http://www.TestPHP.com/HelloWorld /
074. wsdl:input
075. soap:body use= literal /
076. /wsdl:input
077. wsdl:output
078. soap:body use= literal /
079. /wsdl:output
080. /wsdl:operation
081. wsdl:operation name= GetMember
082. soap:operation soapAction= http://www.TestPHP.com/GetMember /
083. wsdl:input
084. soap:body use= literal /
085. /wsdl:input
086. wsdl:output
087. soap:body use= literal /
088. /wsdl:output
089. /wsdl:operation
090. /wsdl:binding
091. wsdl:binding name= TestPHPSoap12 type= tns:TestPHPSoap
092. soap12:binding transport= http://schemas.xmlsoap.org/soap/http /
093. wsdl:operation name= HelloWorld
094. soap12:operation soapAction= http://www.TestPHP.com/HelloWorld /
095. wsdl:input
096. soap12:body use= literal /
097. /wsdl:input
098. wsdl:output
099. soap12:body use= literal /
100. /wsdl:output
101. /wsdl:operation
102. wsdl:operation name= GetMember
103. soap12:operation soapAction= http://www.TestPHP.com/GetMember /
104. wsdl:input
105. soap12:body use= literal /
106. /wsdl:input
107. wsdl:output
108. soap12:body use= literal /
109. /wsdl:output
110. /wsdl:operation
111. /wsdl:binding
112. wsdl:service name= TestPHP
113. wsdl:port name= TestPHPSoap binding= tns:TestPHPSoap
114. soap:address location= http://soap/goodwsdl/testphp.php /
115. /wsdl:port
116. wsdl:port name= TestPHPSoap12 binding= tns:TestPHPSoap12
117. soap12:address location= http://soap/goodwsdl/testphp.php /
118. /wsdl:port
119. /wsdl:service
120. /wsdl:definitions 這里有返回的兩個字段,一個是返回字符串,這個很好理解01. s:element name= HelloWorld
02. s:complexType
03. s:sequence
04. s:element minOccurs= 0 maxOccurs= 1 name= uname type= s:string /
05. s:element minOccurs= 0 maxOccurs= 1 name= upassword type= s:string /
06. /s:sequence
07. /s:complexType
08. /s:element
09. s:element name= HelloWorldResponse
10. s:complexType
11. s:sequence
12. s:element minOccurs= 0 maxOccurs= 1 name= HelloWorldResult type= s:string /
13. /s:sequence
14. /s:complexType
15. /s:element 這一段就字符串的
那返回數組的就比較麻煩了,我和老農搞了一兩周才發現是WSDL文件寫錯了,看下面的一段01. s:element name= GetMember
02. s:complexType
03. s:sequence
04. s:element minOccurs= 1 maxOccurs= 1 name= uid type= s:int /
05. s:element minOccurs= 0 maxOccurs= 1 name= uname type= s:string /
06. /s:sequence
07. /s:complexType
08. /s:element
09. s:element name= GetMemberResponse
10. s:complexType
11. s:sequence
12. s:element minOccurs= 0 maxOccurs= 1 name= GetMemberResult type= tns:ArrayOfMember /
13. /s:sequence
14. /s:complexType
15. /s:element
16. s:complexType name= ArrayOfMember
17. s:sequence
18. s:element minOccurs= 0 maxOccurs= unbounded name= Member nillable= true type= tns:Member /
19. /s:sequence
20. /s:complexType
21. s:complexType name= Member
22. s:sequence
23. s:element minOccurs= 1 maxOccurs= 1 name= UserId type= s:int /
24. s:element minOccurs= 0 maxOccurs= 1 name= Name type= s:string /
25. /s:sequence
26. /s:complexType 第一段GetMember是輸入,最重要的是GetMemberResponse這段,看type= tns:ArrayOfMember 這里,返回一 個數組,WSDL中定義了ArrayOf這個,后面的就簡單了,ArrayOfMember的類型是type= tns:Member ,從name= Member 得到要返回的數組,完工。html教程

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 日韩在线欧美在线 | 欧美性a视频 | 黄色网址免费入口 | 中文字幕精品在线观看 | 一级毛片手机在线观看 | 亚洲免费视频大全 | 一区在线看| 看91 | 国产一区二区欧美 | 日韩毛片免费观看 | 极色品影院 | 国产伦精品一区二区三区在线 | 亚洲性生活视频 | 曰韩黄色片 | 韩国精品久久久 | 国产精品久久久久国产精品三级 | 成人在线观看小视频 | 黄视频网站免费观看 | 羞羞答答影院 | 欧美女优一区 | 国产亚洲精彩视频 | 成人不卡| 19禁国产精品福利视频 | 男女亲热网站 | 一级α片免费看刺激高潮视频 | 日韩深夜视频 | caoporn国产一区二区 | 黄色试看视频 | 成人免费在线观看视频 | 精品99在线视频 | 一区二区三区国产视频 | 色羞羞 | 调教小男生抽打尿孔嗯啊视频 | 视频在线91 | 在线看成人av | 免费看综艺策驰影院 | 欧美成人免费看 | 国产无遮挡一区二区三区毛片日本 | 狠狠色成色综合网 | 精品中文视频 | 国产在线午夜 |