WebService-php- 1(16)

11421 ワード

最近phpのwebserviceに関する資料をたくさん見て、燕十八の分かち合いに感謝して、私のサービス端を構築する過程を助けました.学習ノートには燕十八のノートが含まれている.
WebService
1 WebServiceの迅速な理解
一般的には、一定のXML形式でリモートサーバを呼び出す方法であり、サーバは一定の形式でXML内容を返す.「一定のフォーマット」----SAAP(Simple Object Access Protocol)単純オブジェクトアクセスプロトコルは、分散または分散した環境で情報を交換する単純なプロトコルであり、XMLベースのプロトコルである.リモートサーバ----一般的にHTTPプロトコルを通してメッセージのまとめを伝達する:WebService==HTTPプロトコル+Soap形式のXML
例1:soapリクエスト
  POST/WebServices/MobileCodeWS.asmx HTTP/1.1  Host: webservice.webxml.com.cn  Content-Type: text/xml; charset=utf-8  Content-Length: 354  SOAPAction: "http://WebXml.com.cn/getMobileCodeInfo"    $soap = new soapClient('http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?WSDL'); print_r($soap->getMobileCodeInfo( array('mobileCode'=>'13**********') ) );
Array

(

[0] => getMobileCodeInfoResponse getMobileCodeInfo(getMobileCodeInfo $parameters)

[1] => getDatabaseInfoResponse getDatabaseInfo(getDatabaseInfo $parameters)

)

Array

(

[0] => struct getMobileCodeInfo {

string mobileCode;

string userID;

}

[1] => struct getMobileCodeInfoResponse {

string getMobileCodeInfoResult;

}

[2] => struct getDatabaseInfo {

}

[3] => struct getDatabaseInfoResponse {

ArrayOfString getDatabaseInfoResult;

}

[4] => struct ArrayOfString {

string string;}
//     

print_r($soap->getMobileCodeInfo( array('mobileCode'=>'13426060134') ) );

結果を返す
stdClass Object ( [getMobileCodeInfoResult] => 13*********:                )

3 WebServiceサーバの構築
wsdlは何ですか.wsdlはWebServiceの仕様書です.
<?xml version ='1.0' encoding ='UTF-8' ?>

<definitions name='     [  ]'

targetNamespace='    [   URL]'

xmlns:tns='    [  targetNamespace]'

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>      web service        ,WSDL    XML Schema          ,      Schema      -->

<types>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"

targetNamespace="[   tns]">

</xsd:schema>

</types>

<!--

<message>             ,          .

-->

<message name='   Request'>

<part name="term" type="xsd:string"/>

</message>

<message name='   Response'>

<part name="value" type="xsd:string"/>

</message>

<!--

<portType>         WSDL   .       web service、       ,       .

       WebService    ,        .

-->

<portType name='     '>

<operation name='   '>

<input message='tns:   Request'/>

<output message='tns:   Response'/>

</operation>

</portType>

<!--<binding>                   -->

<binding name='WS      ' type='tns:        '>

<!--style:      "rpc"   "document",ransport:          SOAP   .           HTTP-->

<soap:binding style='rpc'

transport='http://schemas.xmlsoap.org/soap/http'/>

<!--operation                ,      ,    SOAP         -->

<operation name='test'>

<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='WebService  [ weatherWS,shopWS]'>

<port name='WS      [ cartSoap,     ]' binding='tns:[   ,  ]'>

<soap:address location='http://[webservice  ]'/>

</port>

</service>

</definitions>