繁体   English   中英

如何在php中使用soap调用Web服务

[英]how to call web services using soap in php

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.can中使用soap调用autotask的web服务,我们得到了如何调用soap client的示例。

Its output should be like this :

HTTP / 1.1 200 OK内容类型:text / xml; charset = 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>

使用PHP本机SoapClient以及服务WSDL,如下所示:

$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.

至少,你应该瞄准这样的事情。 更多信息可以在这里找到

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM