【发布时间】: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