標籤:http io os 使用 ar 資料 sp art on
項目的需求,需要和一個.net系統進行資料交換,合作方提供了一個WebService介面。這個與一般的PHP POST或GET傳值再查庫拿資料的思路有點不一樣,需要用到SOAP模組,處理方法也很簡單,就是有一些需要注意的事情。
首先確認你的PHP.ini開啟了.SOAP,就是 extension=php_soap.dll 這前面的分號去咯。
代碼很簡單:句容市鄂茂鋼鐵
<?php$client = new SoapClient(‘http://www.nowamagic.net/SearchService.asmx?WSDL‘);$client->soap_defencoding = ‘utf-8‘; $client->decode_utf8 = false; $client->xml_encoding = ‘utf-8‘; $param = array(‘param1‘=>‘01‘, ‘param2‘=>‘02‘);//$param["param1"]="01";//$param["param2"]="02";//$result = $client->__soapCall("GetArticle", array( $param ));$result = $client->__Call("GetArticle", array( $param ));if (is_soap_fault($result)){ trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);}else{ $data = $result->GetArticleResult;//這裡返回的是類,必須使用->得到元素的值 print_r($data);}?>
需要注意的一點是,參數是數組外再包一層數組,就是 array( array() )
附SOAP介面的一些參數:
以下是 SOAP 1.2 請求和響應樣本。所顯示的預留位置需替換為實際值。
POST /SearchService.asmx HTTP/1.1Host: 202.105.183.61Content-Type: text/xml; charset=utf-8Content-Length: lengthSOAPAction: "http://tempuri.org/GetTrafficViolationInfo"<?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> <GetArticle xmlns="http://tempuri.org/"> <param1>string</param1> <param2>string</param2> </GetArticle> </soap:Body></soap:Envelope>
HTTP/1.1 200 OKContent-Type: text/xml; charset=utf-8Content-Length: length<?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> <GetArticleResponse xmlns="http://tempuri.org/"> <GetArticleResult>string</GetArticleResult> </GetArticleResponse> </soap:Body></soap:Envelope>
處理WebService asmx的經驗