PHP: SoapClient 不再按预期工作

PHP: SoapClient no longer working as expected

我对 PHP 不是很有经验,但大约一个月前我写了一个脚本来从 SOAP Web 服务中提取事件数据以显示在数字标牌上。它已经工作了几个星期,但最近坏了。

这是相关的PHP代码...

$WSDL_URL = 'http://anprodca.active.com/uofg/servlet/ActiveNetWS?wsdl';

$params = array(
    "ws_system_user" => $credentials,
    "resource_ids" => array(intval($facilityID)),
    "dates" => $date,
    "include_linked_resources" => 0,
    "returning_render_customer_id" => 0
);

$soap = new SoapClient($WSDL_URL);
$response = $soap->wsGetResourceBookings($params);

... $credentials 包含数组中的 userNamepasswordkeepAlive 值。

当我得到它时,我收到以下异常消息:looks like we got no XML document。我在 Whosebug 上看到过类似的帖子,内容涉及由于麻烦的不可见字符导致格式错误的响应问题,但这里不是这种情况。 __getLastResponse() 的响应似乎是 HTML 来自某种重定向?


我仍然能够使用 SOAPUI 获得所需的结果。以下是它在从 WSDL URL 生成的请求中传递的 XML 的示例:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://ANWebServices/">
    <SOAP-ENV:Body>
        <ns1:wsGetResourceBookings>
            <ws_system_user>
                <keepAlive>false</keepAlive>
                <password>password</password>
                <userName>username</userName>
            </ws_system_user>
            <resource_ids>
                <entries>27</entries>
            </resource_ids>
            <dates>09/25/2016</dates>
            <include_linked_resources>0</include_linked_resources>
            <returning_render_customer_id>0</returning_render_customer_id>
        </ns1:wsGetResourceBookings>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

使用 SoapClient 的跟踪选项和 __getLastRequest() 我得到了以下 XML,当通过 SOAPUI 传递时它也工作正常...

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:anw="http://ANWebServices/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://ANWebServices/">
    <soapenv:Header/>
   <soapenv:Body>
        <anw:wsGetResourceBookings>
         <ws_system_user>
                <keepAlive>false</keepAlive>
            <password>password</password>
            <userName>username</userName>
         </ws_system_user>
         <resource_ids>
            <entries>27</entries>
         </resource_ids>
         <dates>09/25/2016</dates>
         <include_linked_resources>0</include_linked_resources>
         <returning_render_customer_id>0</returning_render_customer_id>
      </anw:wsGetResourceBookings>
   </soapenv:Body>
</soapenv:Envelope>

我以为 WSDL 文件已经更改,但实际上并没有。 服务器端没有任何变化,它仍然使用具有相同配置的相同版本的 PHP 等。我尝试禁用 WSDL 缓存以及 NuSoap 库,但无济于事。我似乎无法弄清楚为什么我无法 PHP 使用 SoapClient 获得正确的响应。任何见解将不胜感激,谢谢!

我能够自己解决这个问题 - 只是张贴这个以防万一有人遇到类似的问题。

他们的 WSDL 文件指定了错误的端点 URL。我只需要使用 __setLocation() 明确指定它。现在我的 PHP 看起来像这样:

...
$soap = new SoapClient($WSDL_URL);
$soap->__setLocation($WSDL_URL);
$response = $soap->wsGetResourceBookings($params);
...

1 行修复