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

标签 php soap

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 的网络服务。我们能得到它的例子吗 我们应该如何调用 soap 客户端。

Its output should be like this :

HTTP/1.1 200 正常 内容类型:文本/xml;字符集=utf-8 Content-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>
 <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.

关于php - 如何在 php 中使用 soap 调用 Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20118839/

相关文章:

php - MySQL覆盖或插入

php - 从 mysql 表匹配 json 数组

php - 如何在 PHP 中将文本转换为图像时加入乌尔都语字母

api - 在 Drupal 中发出 SOAP 请求?

php - 使用 yum 和 pear 安装 php-soap 都失败

php - 在本地 mysql 数据库中缓存 SOAP Web 服务

PHP strtotime() 看起来需要欧元格式

php - 在 WooCommerce 中获取产品类别和标签术语作为元关键字

c# - 来自 NET 客户端的 Apache CXF WS Security WebService - 无法解析用于解包 key 的 KeyInfo

python - XML SOAP POST 错误,我做错了什么?