2014-06-16 105 views
1

请求XMLPHP SOAP请求:XML身体缺少请求

<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包含__getLastRequest生成http://pastie.org/9263788

PHP代码

$options = array("soap_version"=> SOAP_1_1, 
      "trace"=>1, 
      "exceptions"=>0 
      ); 

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

$header[] = new SoapHeader('http://schemas.microsoft.com/ws/2005/05/addressing/none','Action','http://schemas.navitaire.com/WebServices/ISessionManager/Logon',1); 
$header[] = new SoapHeader('http://schemas.navitaire.com/WebServices','ContractVersion','330', false); 

$client->__setSoapHeaders($header); 

$params = array("LogonRequestData" => array("AgentName" => "API*****", 
       "Password" => "Pass****", 
       "RoleCode" => "APIB", 
       "DomainCode" => "WWW")); 

try{ 
$h= $client->Logon($params); 
print nl2br(print_r($h, true)); 
echo 'Request : <br/><xmp>', 
$client->__getLastRequest(); 
echo '</xmp>'; 
} 
catch(SoapFault $fault){ 
echo 'Request : <br/><xmp>', 
$client->__getLastRequest(), 
'</xmp><br/><br/> Error Message : <br/>', 
$fault->getMessage(); 
} 

XML请求()

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.navitaire.com/WebServices/ServiceContracts/SessionService" xmlns:ns2="http://schemas.microsoft.com/ws/2005/05/addressing/none" xmlns:ns3="http://schemas.navitaire.com/WebServices"> 
<SOAP-ENV:Header> 
    <ns2:Action SOAP-ENV:mustUnderstand="1">http://schemas.navitaire.com/WebServices/ISessionManager/Logon</ns2:Action> 
    <ns3:ContractVersion>330</ns3:ContractVersion> 
</SOAP-ENV:Header> 
<SOAP-ENV:Body> 
    <ns1:LogonRequest/> 
</SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

正如你所看到的,XML Body是空的。我如何用参数泛滥身体?

全部输出,蜜蜂在这里看到它被捕获在try{ }http://pastie.org/9295467

在输出中,你还可以看到

//If i use soap version 1.1 
[faultstring] => Bad Request 
[faultcode] => HTTP 

//If i use soap version 1.2 
[faultstring] => Cannot process the message because the content type 'application/soap+xml; charset=utf-8; action="http://schemas.navitaire.com/WebServices/ISessionManager/Logon"' was not the expected type 'text/xml; charset=utf-8'. 
[faultcode] => HTTP 

回答

1

你尝试,因为该错误消息看起来像切换到SOAP_1_2与此相关联。 否则,你可以使用WSDL到php生成器,如WsdlToPhpwsdltophp.com

+0

我试过soap1.2它也会抛出错误,我在我的文章的最后部分突出显示。 –

+0

嗨Mikael wsdltophp工作真棒...我需要在生成的示例文件中设置标题。我如何继续? –

+0

哪些类型的标头:SOAP标头或HTTP标头? –

0

我有同样的问题,并设法使用SOAP_1_1解决它,而不压缩。

所以只需禁用压缩。