我试图在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));
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>
但是从webservice的文档来看,它期待:
<?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达到预期的格式?
答案 0 :(得分:9)
您的结果请求正常(相当于文档中的预期请求)。问题是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。
答案 1 :(得分:0)
请求已成功处理。
try {
if(setEndpoint('changeEndpoint')){
$newLocation = $client->__setLocation(setEndpoint(' https://wsbeta.fedex.com:443/web-services')); // Please set url fedex email response
}
/* echo "<pre>";
Print_r($request); */
$response = $client ->track($request);
}