【问题标题】:"Unable to parse URL" exception after SOAP requestSOAP 请求后出现“无法解析 URL”异常
【发布时间】:2015-03-07 18:48:42
【问题描述】:

我正在尝试将soap 服务与php 一起使用,但似乎该服务无法解释php 创建的请求格式。到目前为止我的简单示例:

ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient('http://publicbetawebservices.hotel.de/V2_8/FreeHotelSearchWebService.svc?WSDL',array("trace"=>1));

try {
  $response = $client->GetWebservicesVersion();
} catch(Exception $e){ 
  print_r($e);
}

输出:

SoapFault Object
(
    [message:protected] => Unable to parse URL
    [string:Exception:private] =>
    [code:protected] => 0
    [file:protected] => /var/www/test.php
    [line:protected] => 6
    [trace:Exception:private] => Array
        (
            [0] => Array
                (
                    [function] => __doRequest
                    [class] => SoapClient
                    [type] => ->
                    [args] => Array
                        (
                            [0] => <?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://webservices.hotel.de/V2_8/"><SOAP-ENV:Body><ns1:GetWebservicesVersion/></SOAP-ENV:Body></SOAP-ENV:Envelope>

                            [1] =>
                            [2] => http://webservices.hotel.de/V2_8/IBaseService/GetWebservicesVersion
                            [3] => 1
                            [4] => 0
                        )

                )

            [1] => Array
                (
                    [file] => /var/www/test.php
                    [line] => 6
                    [function] => __call
                    [class] => SoapClient
                    [type] => ->
                    [args] => Array
                        (
                            [0] => GetWebservicesVersion
                            [1] => Array
                                (
                                )

                        )

                )

            [2] => Array
                (
                    [file] => /var/www/test.php
                    [line] => 6
                    [function] => GetWebservicesVersion
                    [class] => SoapClient
                    [type] => ->
                    [args] => Array
                        (
                        )

                )

        )

    [previous:Exception:private] =>
    [faultstring] => Unable to parse URL
    [faultcode] => HTTP
)

生成的请求 xml 是:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://webservices.hotel.de/V2_8/">
   <SOAP-ENV:Body>
      <ns1:GetWebservicesVersion />
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

但是从 web 服务的文档来看,它是期望的:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <soap:Body>
 <GetWebservicesVersion xmlns="http://webservices.hotel.de/V2_8/"/>
 </soap:Body>
</soap:Envelope>

有没有办法将请求 xml 转换为预期的格式?

【问题讨论】:

    标签: php web-services soap wsdl soap-client


    【解决方案1】:

    您生成的请求正常(相当于文档中的预期请求)。问题是 wsdl http://publicbetawebservices.hotel.de/V2_8/FreeHotelSearchWebService.svc?WSDL 中没有指定端点地址。所以 SoapClient 不知道将请求发布到哪里的 URL,您会收到错误 Unable to parse URL。您必须在代码中手动指定端点 URL。对于 SoapClient,这应该可以工作:

    $client = new SoapClient('http://publicbetawebservices.hotel.de/V2_8/FreeHotelSearchWebService.svc?WSDL',array("trace"=>1));
    $client->__setLocation('http://publicbetawebservices.hotel.de/V2_8/FreeHotelSearchWebService.svc');
    

    也检查这个post

    【讨论】:

      【解决方案2】:

      请求已成功处理。

      try {
      
          if(setEndpoint('changeEndpoint')){
              $newLocation = $client->__setLocation(setEndpoint(' https://wsbeta.fedex.com:443/web-services')); // Please set url fedex email response
          }
          /* echo "<pre>";
           Print_r($request); */
      
          $response = $client ->track($request);
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-10-19
        • 2017-05-05
        • 2020-04-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-02-08
        • 1970-01-01
        相关资源
        最近更新 更多