在PHP中编写SOAP请求以获取自定义XML

时间:2014-06-06 10:00:14

标签: php xml soap

我有一个XML格式。我需要使用PHP将SOAP请求发送到服务器。我正在尝试使用以下代码,但我看到错误。

请在此处找到WSDL

http://pastie.org/9263788

样品申请

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://schemas.navitaire.com/WebServices/ISessionManager/Logon</Action>
<h:ContractVersion xmlns:h="http://schemas.navitaire.com/WebServices">330</h:ContractVersion>
</s:Header>
<s:Body>
<LogonRequest xmlns="http://schemas.navitaire.com/WebServices/ServiceContracts/SessionService">
  <logonRequestData xmlns:d4p1="http://schemas.navitaire.com/WebServices/DataContracts/Session" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <d4p1:DomainCode>WWW</d4p1:DomainCode>
    <d4p1:AgentName>API****</d4p1:AgentName>
    <d4p1:Password>********</d4p1:Password>
    <d4p1:LocationCode i:nil="true" />
    <d4p1:RoleCode>APIB</d4p1:RoleCode>
    <d4p1:TerminalInfo i:nil="true" />
  </logonRequestData>
</LogonRequest>
</s:Body>
</s:Envelope>

守则

<?php
$test->DomainCode = 'CODE';
$test->AgentName = 'AgentName';
$test->Password = 'Password';
$test->RoleCode = 'Role'; 

$wsdl = "https://trtestr3xapi.navitaire.com/sessionmanager.svc?wsdl";
$client = new SoapClient($wsdl);

try {    
$logon_request = $client->Logon($test);
print_r($logon_request);
echo "success!";
} 
catch (SoapFault $soap_error) {
echo $soap_error;
echo "error!";
}
?>

方法名称是登录。我也被给了另一个使用的链接,但我该如何使用它呢?

https://trtestr3xapi.navitaire.com (The urls can't be view from all IPs)

我发送了正确的请求吗?

错误

SoapFault exception: [a:InternalServiceFault] Object reference not set to an instance of an object. in C:\Inetpub\vhosts\ezyflying.com\tiger\index.php:13 Stack trace: #0 C:\Inetpub\vhosts\ezyflying.com\tiger\index.php(13): SoapClient->__call('Logon', Array) #1 C:\Inetpub\vhosts\ezyflying.com\tiger\index.php(13): SoapClient->Logon(Array) #2 {main}error!

以下是我应该得到的回应。

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header />
<s:Body>
<LogonResponse xmlns="http://schemas.navitaire.com/WebServices">
<Signature>signature data</Signature>
</LogonResponse>
</s:Body>
</s:Envelope>

1 个答案:

答案 0 :(得分:1)

您使用本地php数据类型(如数组和对象)并将其传递给SoapClient。对于您的示例,它将类似于:

$test->DomainCode = 'CODE',
$test->AgentName = 'AgentName',
$test->Password = 'Password',
$test->RoleCode = 'Role';

$wsdl = "https://trtestr3xapi.navitaire.com/sessionmanager.svc?wsdl";

$client = new SoapClient($wsdl);

try {    
    $logon_request = $client->Logon($test);
    print_r($logon_request);
    echo "success!";
} catch (SoapFault $soap_error) {
    echo $soap_error;
    echo "error!";
}