PHP Soap Request:请求中缺少XML正文

阿西克·巴舍尔(Ashik Basheer)

要求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主体为空。如何用参数填充身体?

在此处可以看到完整的输出,该输出捕获在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
米卡·德尔索(MikaëlDELSOL)

您是否尝试过切换到SOAP_1_2,因为错误消息看起来像与此相关联。否则,你可以使用WSDL的PHP发电机如WsdlToPhpwsdltophp.com

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章