2015-03-02 83 views
-1

我有一個網站需要發送請求到另一臺服務器並檢索一些數據。我對SOAP一無所知,所以我需要一個專家幫助。通過PHP訪問SOAP

這是第二臺服務器給我的數據。 我不知道從哪裏開始以及如何去做。所以,任何幫助表示讚賞。 你能否給我一個適用於此代碼的php代碼的工作示例。

SOAP 1.1

以下是示例SOAP 1.1請求和響應。顯示的佔位符需要用實際值替換。

POST /Service1.asmx HTTP/1.1 
Host: puanreport.retail.az 
Content-Type: text/xml; charset=utf-8 
Content-Length: length 
SOAPAction: "http://tempuri.org/_find" 

<?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> 
    <_find xmlns="http://tempuri.org/"> 
     <par>string</par> 
    </_find> 
    </soap:Body> 
</soap:Envelope> 
HTTP/1.1 200 OK 
Content-Type: text/xml; charset=utf-8 
Content-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> 
    <_findResponse xmlns="http://tempuri.org/"> 
     <_findResult> 
     <bon> 
      <Cari_Kod>string</Cari_Kod> 
      <Puan>string</Puan> 
     </bon> 
     <bon> 
      <Cari_Kod>string</Cari_Kod> 
      <Puan>string</Puan> 
     </bon> 
     </_findResult> 
    </_findResponse> 
    </soap:Body> 
</soap:Envelope> 
+0

可能重複[如何使用香皂類的PHP(帶有示例)?](http://stackoverflow.com/questions/9018236/how-to-use-soap-class-in- PHP與 - 例如) – Martin 2015-03-02 10:30:26

回答

0

最簡單的方法是:

$client = new SoapClient('http://www.webservicex.net/geoipservice.asmx?WSDL'); 
$result = $client->GetGeoIP(array('IPAddress' => '8.8.8.8')); 

print_r($result); 

這給你:

stdClass Object 
(
    [GetGeoIPResult] => stdClass Object 
     (
      [ReturnCode] => 1 
      [IP] => 8.8.8.8 
      [ReturnCodeDetails] => Success 
      [CountryName] => United States 
      [CountryCode] => USA 
     ) 

) 

現在,你可以簡單地通過調用

$country = $result->GetGeoIPResult->CountryName; 

已經回答了訪問值here

php.net soap class