【问题标题】:PHP: SoapClient no longer working as expectedPHP:SoapClient 不再按预期工作
【发布时间】:2016-09-25 22:00:29
【问题描述】:

我对 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。我在 stackoverflow 上看到过类似的帖子,关于由于麻烦的不可见字符导致的格式错误的响应问题,但这里不是这种情况。 __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>

将 trace 选项和 __getLastRequest() 与 SoapClient 一起使用,我得到了以下 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 得到正确的响应。任何见解将不胜感激,谢谢!

【问题讨论】:

  • “来自 __getLastResponse() 的响应似乎是来自某种重定向的 HTML” ...如果服务突然给你一个重定向我'我不确定你希望这里的人帮你什么。与运行它的人交谈。也许他们对您调用它的 IP 地址进行了速率限制,也许他们完全做了其他事情。
  • “如果服务突然给你一个重定向,我不确定你希望这里的人能帮你什么”......我想弄清楚为什么我能得到一个使用 SOAPUI 而不是 SoapClient/PHP 的有效 XML 响应“也许他们已经限制了您从中调用它的 IP 地址”......那么它不适用于 SOAPUI
  • SOAPUI 是一个客户端应用程序 - 如果他们对您的服务器的 IP 地址进行了限制(不清楚您是否从其他任何地方尝试过 SoapClient),它不会对其产生任何影响。

标签: php xml web-services soap soapui


【解决方案1】:

我能够自己解决这个问题——只是发布这个以防万一有人遇到类似问题。

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

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

1 行修复?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-15
    相关资源
    最近更新 更多