douzha8489 2015-03-07 18:48
浏览 94
已采纳

SOAP请求后“无法解析URL”异常

I'm trying to use a soap service with php, but it seems that the request format that php creates couldn't be interpreted by the service. Simple example I have so far:

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);
}

Output:

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
)

The resulting request xml is:

<?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>

But as of the documentation of the webservice, it is expecting:

<?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>

Is there a way to get the request xml to the expected format?

  • 写回答

2条回答 默认 最新

  • dqwn64004 2015-03-07 20:19
    关注

    Your resulting request is OK (equivalent to expected request from documentation). Problem is there is no endpoint address specified in wsdl http://publicbetawebservices.hotel.de/V2_8/FreeHotelSearchWebService.svc?WSDL. So SoapClient does not know URL where to post the request and you get error Unable to parse URL. You have to specify endpoint URL manually in code. For SoapClient this should work:

    $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');
    

    Check this post also.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀