“无法解析 URL"SOAP 请求后的异常 [英] "Unable to parse URL" exception after SOAP request

查看:61
本文介绍了“无法解析 URL"SOAP 请求后的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用带有 php 的soap 服务,但该服务似乎无法解释php 创建的请求格式.到目前为止,我有一个简单的例子:

ini_set("soap.wsdl_cache_enabled", "0");$client = new SoapClient('http://publicbetawebservices.hotel.de/V2_8/FreeHotelSearchWebService.svc?WSDL',array("trace"=>1));尝试 {$response = $client->GetWebservicesVersion();} catch(异常$e){打印_r($e);}

输出:

SoapFault 对象([消息:受保护] =>无法解析网址[字符串:异常:私有] =>[代码:受保护] =>0[文件:受保护] =>/var/www/test.php[行:受保护] =>6[trace:Exception:private] =>大批([0] =>大批([功能] =>__doRequest[类] =>肥皂客户端[类型] =>->[参数] =>大批([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] =>大批([文件] =>/var/www/test.php[行] =>6[功能] =>__称呼[类] =>肥皂客户端[类型] =>->[参数] =>大批([0] =>获取网络服务版本[1] =>大批()))[2] =>大批([文件] =>/var/www/test.php[行] =>6[功能] =>获取网络服务版本[类] =>肥皂客户端[类型] =>->[参数] =>大批()))[上一个:例外:私有] =>[故障字符串] =>无法解析网址[故障代码] =>HTTP)

生成的请求xml是:

但是根据网络服务的文档,它是期望的:

<肥皂:身体><GetWebservicesVersion xmlns="http://webservices.hotel.de/V2_8/"/></soap:Body></soap:Envelope>

有没有办法让请求的xml变成预期的格式?

解决方案

您生成的请求没问题(相当于文档中的预期请求).问题是 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');

也请查看此帖子.>

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?

解决方案

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.

这篇关于“无法解析 URL"SOAP 请求后的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆