處理WebService asmx的經驗

來源:互聯網
上載者:User

標籤:style   http   color   io   os   使用   ar   資料   div   

項目的需求,需要和一個.net系統進行資料交換,合作方提供了一個WebService介面。這個與一般的PHP POST或GET傳值再查庫拿資料的思路有點不一樣,需要用到SOAP模組,處理方法也很簡單,就是有一些需要注意的事情。大都會娛樂城

首先確認你的PHP.ini開啟了.SOAP,就是 extension=php_soap.dll 這前面的分號去咯。

代碼很簡單:

view source print?
01 <?php
02  
03 $client = new SoapClient(‘http://www.nowamagic.net/SearchService.asmx?WSDL‘);
04  
05 $client->soap_defencoding = ‘utf-8‘; 
06 $client->decode_utf8 = false;  
07 $client->xml_encoding = ‘utf-8‘;
08  
09 $param = array(‘param1‘=>‘01‘, ‘param2‘=>‘02‘);
10  
11 //$param["param1"]="01";
12 //$param["param2"]="02";
13  
14 //$result = $client->__soapCall("GetArticle", array( $param ));
15 $result = $client->__Call("GetArticle", array( $param ));
16  
17 if (is_soap_fault($result))
18 {
19     trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
20 }
21 else
22 {
23     $data = $result->GetArticleResult;   //這裡返回的是類,必須使用->得到元素的值
24     print_r($data);
25 }
26 ?>

需要注意的一點是,參數是數組外再包一層數組,就是 array( array() )

附SOAP介面的一些參數:

以下是 SOAP 1.2 請求和響應樣本。所顯示的預留位置需替換為實際值。

view source print?
01 POST /SearchService.asmx HTTP/1.1
02 Host: 202.105.183.61
03 Content-Type: text/xml; charset=utf-8
04 Content-Length: length
05 SOAPAction: "http://tempuri.org/GetTrafficViolationInfo"
06  
07 <?xml version="1.0" encoding="utf-8"?>
08 <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/">
09   <soap:Body>
10     <GetArticle xmlns="http://tempuri.org/">
11       <param1>string</param1>
12       <param2>string</param2>
13     </GetArticle>
14   </soap:Body>
15 </soap:Envelope>
view source print?
01 HTTP/1.1 200 OK
02 Content-Type: text/xml; charset=utf-8
03 Content-Length: length
04  
05 <?xml version="1.0" encoding="utf-8"?>
06 <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/">
07   <soap:Body>
08     <GetArticleResponse xmlns="http://tempuri.org/">
09       <GetArticleResult>string</GetArticleResult>
10     </GetArticleResponse>
11   </soap:Body>
12 </soap:Envelope>

處理WebService asmx的經驗

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.