我需要从 http://ws.jrtwebservices.com/jrtlowfaresearch/jrtlfs.asmx 获取数据,此服务需要凭据信息,例如ID,用户ID和系统值。我将这些信息放入一个字符串中:
$xml_post_string = "<POS><Source> <RequestorID Type='21' ID='xxx'/> </Source> <TPA_Extensions> <Provider><System>xxx</System> <Userid>xxx</Userid> </Provider></TPA_Extensions></POS>"
我还定义了 SoapClient:
$client = new SoapClient(null, array('uri' => "http://ws.jrtwebservices.com",
'location => "http://ws.jrtwebservices.com/jrtlowfaresearch/jrtlfs.asmx") );
我称肥皂为:
$response = $client->__soapCall('do_LowfareSearch',array($xml_post_string),array('soapaction' => 'http://jrtechnologies.com/do_LowfareSearch'));
有人知道为什么我得到空的回应吗?
非常感谢!
使用您的代码,请求如下所示:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xm...">
<SOAP-ENV:Body>
<ns1:do_LowfareSearch>
<param0 xsi:type="xsd:string">
"<POS><Source> <RequestorID Type='21' ID='xxx'/> </Source> <TPA_Extensions> <Provider <System>xxx</System> <Userid>xxx</Userid> </Provider></TPA_Extensions></POS>"
</param0>
</ns1:do_LowfareSearch>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
客户端使用了您传递的方法,但无法按照您为其提供的方式构建参数。您的所有参数都位于<param0>
内部" "
。
(此外,您缺少'
后的位置。 'location => "http:...
)
当你要设置 WSDL 的 SOAP 客户端时,它将为你完成所有的 XML 格式设置。
WSDL 中应该包含位置,因此您无需担心这一点。
我喜欢使用 WSDL 验证器来测试方法并查看它们的参数。
您应该构建要作为数组或类传递的信息,并让 SOAP 客户端和 WSDL 将其转换为所需的 XML。
所以像这样的东西就是你正在寻找的:
<?php
//SOAP Client
$wsdl = "http://ws.jrtwebservices.com/jrtlowfaresearch/jrtlfs.asmx?WSDL";
$client = new SoapClient($wsdl, array( 'soap_version' => SOAP_1_1,
'trace' => true, //to debug
));
try {
$args = array(
'companyname'=> 'xxx',
'name'=> 'xxx',
'system'=> 'xxx',
'userid'=> 'xxx',
'password'=> 'xxx',
'conversationid'=>'xxx',
'entry'=> 'xxx',
);
$result = $client->__soapCall('do_LowfareSearch', $args);
return $result;
} catch (SoapFault $e) {
echo "Error: {$e}";
}
//to debug the xml sent to the service
echo($client->__getLastRequest());
//to view the xml sent back
echo($client->__getLastResponse());
?>