CentOS SOAP擴展模塊觸發(fā)Service端執(zhí)行相應(yīng)的操作
CentOS SOAP對于電腦使用的玩家的常用軟件,然后我就學(xué)習(xí)及深入的研究CentOS SOAP,在這里和大家一起探討CentOS SOAP的使用方法,希望對大家有用。從PHP5開始內(nèi)置CentOS SOAP擴展模塊,通過它,我們可以方便的向Service發(fā)送一個CentOS SOAP消息,從而觸發(fā)Service端執(zhí)行相應(yīng)的操作,并將結(jié)果返回;
首先,要確保安裝了CentOS SOAP擴展,沒有安裝的表現(xiàn)是,當(dāng)運行使用了soapclient的代碼時候會有php error Class ‘SoapClient’ not found的錯誤;這時候應(yīng)該安裝php-soap,在CentOS SOAP上可以方便的使用yum更新安裝包>yum install php-soap更新過這些安裝包后,需要重新啟動一下apache服務(wù),此后SoapClient類就可以用在php script中了下邊是使用過程中的一個范例:
- <?php
- $client = new SoapClient("some.wsdl");
- $client->SomeFunction($a, $b, $c);
- $arr= $client->__soapCall("SomeFunction", array($a, $b, $c));
- print_r($arr);
- ?>
1.in WSDL mode,soapCall應(yīng)用web service,例子用的是asp.net的web service,提供service.asmx頁面,調(diào)用及查看都比較簡單,手冊上的example也大多是這個類型,比較簡單
CentOS SOAP發(fā)送的協(xié)議:
- POST /servicepath/service.asmx HTTP/1.1
- Host: 211.186.1.4
- Content-Type: text/xml; charset=utf-8
- Content-Length: length
- SOAPAction: "http://211.186.5.15/Service/ServiceMethod"
- <?xml version="1.0" encoding="utf-8"?>
- <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:xsd="http://www.w3.org/2001/XMLSchema"
- xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
- <soap:Body>
- <ServiceMethod xmlns="http://211.186.5.15/Service">
- <param1>string</param1>
- <param2>string</param2>
- <param3>string</param3>
- </ServiceMethod>
- </soap:Body>
- </soap:Envelope>
調(diào)用方法:
- $client = new SoapClient("http://www.xxx.com/service/service.asmx?WSDL");
- //向SOAP服務(wù)方發(fā)送參數(shù)值
- $param1 = "p1";
- $param2 = "p2";
- $param3 = "p3";
//serviceParam1,serviceParam2,serviceParam3為發(fā)送參數(shù)值所對應(yīng)的參數(shù)名(或service端提供的字段名) $param = array('serviceParam1' => $param1,'serviceParam2' => $param2,'serviceParam3' => $param3);
//方法名為ServiceMethod,參數(shù)數(shù)組為$param,默認以parameters字段標(biāo)示傳遞的參數(shù)數(shù)組 $arr = $client->__soapCall('ServiceMethod',array('parameters' => $param)); print_r($arr);
此處,print_r($arr)打印出來的是一個對象,類似于
- stdClass Object
- ( [BindValidateResult] => 01062947546 )
經(jīng)過我多次的嘗試,發(fā)現(xiàn)使用$arr[1],$arr[0],$arr[BindValidateResult]均不能取得有效值;后來查詢到通過$arr->BindValidateResult可以訪問到返回值;
【編輯推薦】