2014-06-06 41 views
0

我有一個XML格式。我需要使用PHP將SOAP請求發送到服務器。我試着用下面的代碼,但我看到錯誤。用PHP寫一個自定義XML的SOAP請求

請在這裏找到

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> 

的WSDL守則

<?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> 
+0

您不會使用SoapClient發送原始XML soap請求。它將本地對象轉換爲XML – Anthony

+0

行。請查看與pastie鏈接提供的WSDL。你也可以幫我設置肥皂請求與適當的PHP代碼? –

回答

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

我得到相同的錯誤。你見過我編輯的問題嗎?我已經給了另一個鏈接加入。 –

+0

您可能會得到相同的錯誤,但出於不同的原因。該錯誤表明使用了非對象,因此可能SoapClient或遠程SOAP服務器無法在數組和對象之間儘可能地進行交換,因此可以使用值傳入對象。更新的答案。 – Anthony

+0

此外,您的更新顯示您正在傳入數組,但也顯示您仍在傳遞原始XML。是這樣嗎? – Anthony