用PHP为自定义XML编写SOAP请求


Write a SOAP request in PHP for a custom XML

我有一个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!";
}
?>

方法名称是Logon。我也有另一个链接使用,但我如何使用它?

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>

使用本地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!";
}