PHP:编写包含XML数据和SOAPHeader的SOAP请求

PHP:编写包含XML数据和SOAPHeader的SOAP请求,php,xml,web-services,soap,wsdl,Php,Xml,Web Services,Soap,Wsdl,嗨,我有一个PHP SOAP请求的问题,我已经用尽了在web上找到的示例。下面是我需要发送的请求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://sche

嗨,我有一个PHP SOAP请求的问题,我已经用尽了在web上找到的示例。下面是我需要发送的请求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>
我已经使用
$client->\uu getFunctions()生成了函数。

并且类型在该链接中

WSDL中包含的链接
具有ContractVersion信息

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.navitaire.com/WebServices" elementFormDefault="qualified" targetNamespace="http://schemas.navitaire.com/WebServices">
<xs:element name="ContractVersion" type="xs:int"/>
<xs:element name="LogonResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="Signature" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Signature" nillable="true" type="xs:string"/>
</xs:schema>

该错误表示声明标头时使用的命名空间中的标头
ContractVersion
“未理解”。这是因为在该目标命名空间的模式中可能没有声明
ContractVersion
元素

根据您的SOAP请求,ContractVersion属于另一个命名空间:

<h:ContractVersion xmlns:h="http://schemas.navitaire.com/WebServices">
对于
LogonRequest
数据,根据您希望生成的结果,您需要向其中添加
LogonRequestData
对象。您的模式不可用,我不知道使用PHPAPI的确切语法。一种方法是将负载添加为文本XML。您可能需要在SOAP客户端中为此设置一些配置,我不确定这是否是PHP推荐的标准过程。如果可以发送文本XML,则可以使用下面的代码构建一个类似于您发布的对象的

$ns_d4p1 = 'http://schemas.navitaire.com/WebServices/DataContracts/Session';
$ns_i = 'http://www.w3.org/2001/XMLSchema-instance';

$logonResquestData = new SimpleXMLElement("<logonRequestData xmlns:i='$ns_i' xmlns:d4p1='$ns_d4p1' />");

$logonResquestData->addChild('d4p1:DomainCode', 'WWW', $ns_d4p1);
$logonResquestData->addChild('d4p1:AgentName', 'API****', $ns_d4p1);
$logonResquestData->addChild('d4p1:Password', '****', $ns_d4p1);
$logonResquestData->addChild('d4p1:LocationCode', null, $ns_d4p1)->addAttribute('i:nil', 'true', $ns_i);
$logonResquestData->addChild('d4p1:RoleCode', 'APIB', $ns_d4p1);
$logonResquestData->addChild('d4p1:TerminalInfo', null, $ns_d4p1)->addAttribute('i:nil', 'true', $ns_i);

现在,您必须将该对象作为参数传递给
Logon
操作,从而将其添加到
LogonRequest
对象中。我不确定确切的语法。您可能需要添加或。您建议使用数组。无论是哪种方法,在尝试发送之前都必须测试它并查看它是否生成了正确的XML。这样调试会更容易。

Hi!很高兴再次见到你哦,这是同样的问题。还是没修好?如果不查看您的模式(
LogonRequest
元素),很难知道您的请求应该如何形成。我想让您访问我的服务器,以便您可以查看。关于同一个问题,我提出了很多问题:(不幸的是,我不能向任何人寻求帮助。你能通过teamviewer帮我解决吗?我知道der应该是一个简单的修复程序,但我不知道SOAP或XMLOpen模式,它包含
LoginRequest
的元素声明。在你之前的问题中,你将其包含在
LoginResponse
中,因此应该不难找到它。或者,您可以将该架构放在此处或粘贴箱中。这会很有帮助。LogonRequest位于我添加到回答信息的url中,关于创建您作为soap请求参数发送的数据。我希望它可以帮助您解决问题。我回滚了上一个问题。如果您进行了彻底的编辑,从而更改了问题,请使用您的帐户可能被标记。如果您有一个新主题,请创建一个新问题解决它,并链接到上一个问题。谢谢您的提示:)由于您解决了标题问题,我实际上建议您创建一个新问题,重点是将参数传递给soap客户端。为了方便那些试图回答这个问题的人,您应该在问题中包含相关代码的摘录,即:WSDL、
LogonRequest
logonRe的模式定义questData
和每个
logonRequestData
子元素。没有这些信息,你将很难得到一个好的答案。写一个清晰、客观的问题,用一个清晰的标题来处理一个问题。你的机会会更高。我一定会尝试:)
$wsdl = 'https://trtestr3xapi.navitaire.com/sessionmanager.svc?wsdl';
$header = new SoapHeader('http://schemas.navitaire.com/WebServices','ContractVersion','330', '1');

$ns_d4p1 = 'http://schemas.navitaire.com/WebServices/DataContracts/Session';
$ns_i = 'http://www.w3.org/2001/XMLSchema-instance';

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

$logonResquestData = new SimpleXMLElement("<logonRequestData xmlns:i='$ns_i' xmlns:d4p1='$ns_d4p1' />");

$logonResquestData->addChild('d4p1:DomainCode', 'WWW', $ns_d4p1);
$logonResquestData->addChild('d4p1:AgentName', 'APISERANGOONAT', $ns_d4p1);
$logonResquestData->addChild('d4p1:Password', 'Newskies-1', $ns_d4p1);
$logonResquestData->addChild('d4p1:LocationCode', null, $ns_d4p1)->addAttribute('i:nil', 'true', $ns_i);
$logonResquestData->addChild('d4p1:RoleCode', 'APIB', $ns_d4p1);
$logonResquestData->addChild('d4p1:TerminalInfo', null, $ns_d4p1)->addAttribute('i:nil', 'true', $ns_i);

//var_dump($logonResquestData->asXML());

$logon_request = $client->Logon($logonResquestData);

return $logon_request;
Fatal error: Uncaught SoapFault exception: [a:InternalServiceFault] LogonRequest.AgentName:LengthStringAttribute: The value of LogonRequest.AgentName:LengthStringAttribute is empty, but is not optional. in C:\Inetpub\vhosts\ezyflying.com\tiger\x.php:22 Stack trace: #0 C:\Inetpub\vhosts\ezyflying.com\tiger\x.php(22): SoapClient->__call('Logon', Array) #1 C:\Inetpub\vhosts\ezyflying.com\tiger\x.php(22): SoapClient->Logon(Object(SimpleXMLElement)) #2 {main} thrown in C:\Inetpub\vhosts\ezyflying.com\tiger\x.php on line 22
<h:ContractVersion xmlns:h="http://schemas.navitaire.com/WebServices">
$header = new SoapHeader('http://schemas.navitaire.com/WebServices','ContractVersion','330', '1');
$ns_d4p1 = 'http://schemas.navitaire.com/WebServices/DataContracts/Session';
$ns_i = 'http://www.w3.org/2001/XMLSchema-instance';

$logonResquestData = new SimpleXMLElement("<logonRequestData xmlns:i='$ns_i' xmlns:d4p1='$ns_d4p1' />");

$logonResquestData->addChild('d4p1:DomainCode', 'WWW', $ns_d4p1);
$logonResquestData->addChild('d4p1:AgentName', 'API****', $ns_d4p1);
$logonResquestData->addChild('d4p1:Password', '****', $ns_d4p1);
$logonResquestData->addChild('d4p1:LocationCode', null, $ns_d4p1)->addAttribute('i:nil', 'true', $ns_i);
$logonResquestData->addChild('d4p1:RoleCode', 'APIB', $ns_d4p1);
$logonResquestData->addChild('d4p1:TerminalInfo', null, $ns_d4p1)->addAttribute('i:nil', 'true', $ns_i);
print_r($logonResquestData->asXML());