PHP Soap 请求:请求中缺少 XML 正文 [英] PHP Soap Request: XML Body missing in the request

查看:30
本文介绍了PHP Soap 请求:请求中缺少 XML 正文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请求 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 正文是空的.我如何用参数淹没主体?

As you can see the XML Body is empty. How do I flood the body with the parameters?

在这里可以看到完整的输出,它被捕获在 try{ }http://pastie.org/9295467

Full output can bee seen here which is caught in the try{ } block 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

推荐答案

您是否尝试切换到 SOAP_1_2,因为错误消息似乎与此相关.否则,您可以在 wsdltophp.com

Did you try switching to SOAP_1_2 because the error message looks like to be associated to this. Otherwise, you could use a WSDL to php generator such as WsdlToPhp at wsdltophp.com

这篇关于PHP Soap 请求:请求中缺少 XML 正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆