如何在PHP中使用SOAP调用Web服务

3
The following is a sample SOAP 1.1 request and response.:
POST /atservices/1.5/atws.asmx HTTP/1.1
Host: webservices2.autotask.net
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://autotask.net/ATWS/v1_5/getZoneInfo"

<?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>
  <getZoneInfo xmlns="http://autotask.net/ATWS/v1_5/">
  <UserName>string</UserName>
  </getZoneInfo>
 </soap:Body>
</soap:Envelope>

我们希望在PHP中使用SOAP调用Autotask的Web服务。能否提供一个示例,说明如何调用SOAP客户端?
Its output should be like this :

HTTP/1.1 200 OK 内容类型: 文本/xml; 字符集=utf-8 内容长度: 长度

<?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>
 <getZoneInfoResponse xmlns="http://autotask.net/ATWS/v1_5/">
  <getZoneInfoResult>
    <URL>string</URL>
    <ErrorCode>int</ErrorCode>
    <DataBaseType>string</DataBaseType>
    <CI>int</CI>
  </getZoneInfoResult>
 </getZoneInfoResponse>
 </soap:Body>
 </soap:Envelope>
2个回答

2
使用PHP本地的SoapClient与服务WSDL一起使用,如下所示:

SoapClient

$atservices_wsdl = "https://www.autotask.net/atservices/1.5/atws.wsdl";
$atservices_client = new SoapClient($atservices_wsdl);

$zone_info = $atservices_client->getZoneInfo("SomeUserName");

print_r($zone_info); // review the returned object converted from SOAP response.

echo $zone_info->DataBaseType; // this might work if it's not behind a Response object.

2

至少,你应该争取达到这个水平。更多信息可以在这里找到。

$soap = new SoapClient('link/to/.wsdl');
$result = $soap->__soapCall('getZoneInfo', array('UserName' => $username));
var_dump($result);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接