【问题标题】:Unable to set SOAP header with mustUnderstand无法使用 mustUnderstand 设置 SOAP 标头
【发布时间】:2014-06-07 16:31:03
【问题描述】:

以下是请求 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>

以下是我的 PHP 代码。

$test->DomainCode = 'WWW';
$test->AgentName = 'AGENT';
$test->Password = 'PASS';
$test->RoleCode = 'ROLE';

$wsdl = "https://trtestr3xapi.navitaire.com/sessionmanager.svc?wsdl";

$client = new SoapClient($wsdl, array('trace' => 1));


$header = new SoapHeader('h','ContractVersion','330', '1');
$client->__setSoapHeaders($header);

...

对于上面的代码,我得到以下错误。

SoapFault exception: [s:MustUnderstand] The header 'ContractVersion' from the namespace 'h' was not understood by the recipient of this message, causing the message to not be processed. This error typically indicates that the sender of this message has enabled a communication protocol that the receiver cannot process. Please ensure that the configuration of the client's binding is consistent with the service's binding.

我该如何解决这个问题?由于只能从特定 IP 访问 WSDL,因此我在下面给出了链接

WSDL:http://pastie.org/9263788

【问题讨论】:

  • 您能否也包含来自此命名空间的 XSD 链接:https://trtestr3xapi.navitaire.com/SessionManager.svc?xsd=xsd3?它无法从 WSDL 访问,它声明了您遇到问题的元素。
  • 我不熟悉 SOAP 概念。能详细点吗?
  • 您可以在本地访问的上述 URL 指向一个文件(XSD 架构)。它由您的 WSDL 自动导入。在其中有一个ContractVersion 的元素声明。如果您也可以发布该文件,它可能有助于诊断问题。
  • 我认为它在此链接中可见 pastie.org/9263788 如果这不是您所指的那个,那么我需要询问 API 提供者。
  • 在那个链接中您发布了 WSDL 文档。该文档包含以下标签:&lt;xsd:import schemaLocation="https://trtestr3xapi.navitaire.com/SessionManager.svc?xsd=xsd3" namespace="http://schemas.navitaire.com/WebServices"/&gt;,它指的是 XSD,它描述了 http://schemas.navitaire.com/WebServices 命名空间中的元素。您发布的链接中没有关于ContractVersion 的信息。该信息在 XSD 中。

标签: php xml soap


【解决方案1】:

根据SOAPHeader 文档,语法应该是:

SoapHeader ( string $namespace , string $name , mixed $data , bool $mustunderstand )

在您的代码中,您将 命名空间前缀 放置在命名空间应位于的位置:

$header = new SoapHeader('h','ContractVersion','330', '1');

将该行更改为:

$header = new SoapHeader('http://schemas.navitaire.com/WebServices','ContractVersion','330', 'true');

【讨论】:

  • 这给出了错误 SoapFault 异常:[a:InternalServiceFault] 对象引用未设置为对象的实例。在 C:\Inetpub\vhosts\ezyflying.com\tiger\index.php:19 堆栈跟踪:#0 C:\Inetpub\vhosts\ezyflying.com\tiger\index.php(19): SoapClient->__call(' Logon', Array) #1 C:\Inetpub\vhosts\ezyflying.com\tiger\index.php(19): SoapClient->Logon(Object(stdClass)) #2 {main}error!
  • 该错误意味着标题已被理解,并且您在问题中提出的问题已解决。你现在有另一个问题,值得另一个问题。当您制定其他问题时,您应该包括 Logon 类型的 XSD,这会导致该错误(您可能没有以 Logon 对象所需的结构发送数据)
  • 另外,您的 Logon 对象似乎需要一个数组。 XSD 可以显示该数组应包含的内容。根据您的配置,您可能能够在实例化SoapClient 时发送登录凭据。无论如何,这是另一个问题。
  • 啊!你能用我需要发送数据的结构来更新你的答案吗?我已经厌倦了尝试不同的方法并且筋疲力尽......或者你可以给我提示,以便我可以尝试。
  • 我不知道。您没有来自该服务的文档吗? XSD 将描述Logon 对象的结构,但我不能保证它就足够了。您可能还需要处理其他细节。您应该向您的提供商索取连接到该服务的示例应用程序,并将其用作起点。
猜你喜欢
  • 1970-01-01
  • 2013-08-30
  • 1970-01-01
  • 2011-05-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-28
相关资源
最近更新 更多