php - "Unable to parse URL"SOAP 请求后异常

标签 php web-services soap wsdl soap-client

我正在尝试将 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格式达到预期的格式?

最佳答案

您的结果请求是可以的(等同于文档中的预期请求)。问题是 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还有。

关于php - "Unable to parse URL"SOAP 请求后异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28918666/

相关文章:

php - Magento getModel ('catalog/product' )->getCollection() with addAttributeToSelect ('*' ) 不返回描述

php - Paypal 监听器 : Connection reset by peer?

wcf - WCF 服务与 Web 服务和 REST 服务的区别

java - 如何使用 WSDL

javascript - 如何从 Javascript/jQuery 调用 SOAP WS

php - Laravel:类 Illuminate\Database\Eloquent\Builder 的对象无法转换为字符串

php - 在 Vagrant 中使用 XDEBUG

java - 基于中间件的 HTTP/JMS 混合 SOAP 的请求-回复模型

java - 使用依赖注入(inject)实现数据访问 API

java - 尝试与端点通信时无法识别 WSDL 类型