我需要从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") );
我将soapCall称为:
$response = $client->__soapCall('do_LowfareSearch',array($xml_post_string),array('soapaction' => 'http://jrtechnologies.com/do_LowfareSearch'));
有人知道为什么我会得到空洞的回应吗?
非常感谢!
答案 0 :(得分:2)
使用您的代码,请求如下所示:
<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:...
)
当您创建SOAP客户端时,您想要设置WSDL,它将为您执行所有XML格式化。
The WSDL应该包含该位置,因此您无需担心这一点。
I like to use a WSDL validator to test out the methods and see their parameters.
您应该将要传递的信息构造为arrays or a classes,并让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());
?>