PHP Soap请求:请求中缺少XML Body

时间:2014-06-16 16:00:53

标签: php xml 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包含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(); 
} 

从__getLastRequest()

生成的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

2 个答案:

答案 0 :(得分:1)

您是否尝试切换到SOAP_1_2,因为错误消息看起来与此相关联。 否则,您可以在WsdlToPhp

使用WSDL到php生成器,例如wsdltophp.com

答案 1 :(得分:0)

我遇到了同样的问题,并设法使用SOAP_1_1进行无压缩修复。

所以只需禁用压缩。