2015-03-02 79 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