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

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 vhdl+MODELSIM
  • ¥20 simulink中怎么使用solve函数?
  • ¥30 dspbuilder中使用signalcompiler时报错Error during compilation: Fitter failed,求解决办法
  • ¥15 gwas 分析-数据质控之过滤稀有突变中出现的问题
  • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
  • ¥15 知识蒸馏实战博客问题
  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题