Ashik Basheer
Ashik Basheer

Reputation: 1601

Write a SOAP request in PHP for a custom XML

I have got a XML format. I need to send SOAP request to the server using PHP. I'm trying with the following code but I see error.

Please find the WSDL here

http://pastie.org/9263788

Sample Request

<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>

The Code

<?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!";
}
?>

Method name is Logon. I have also been given another link to use but how do I use this?

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

Am I sending correct request??

Error

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!

Following is the response I should be getting.

<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>

Upvotes: 0

Views: 631

Answers (1)

Anthony
Anthony

Reputation: 37045

You use local php data types (like arrays and objects) and pass those to the SoapClient. For your example, it would be something like:

$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!";
}

Upvotes: 1

Related Questions