2016-03-04 94 views
0

在PHP中,我需要创造这样PHP SOAP:如何获得XML头和身体标记内PARAM

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"> 

    <SOAP-ENV:Header xmlns:NS1="urn:UCoSoapDispatcherBase" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
    <NS1:TAuthenticationHeader xsi:type="NS1:TAuthenticationHeader"> 
    <UserName xsi:type="xsd:string">user</UserName> 
    <Password xsi:type="xsd:string">pass</Password> 
    </NS1:TAuthenticationHeader> 
    </SOAP-ENV:Header> 
    <SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
    <NS2:ExecuteRequest xmlns:NS2="urn:UCoSoapDispatcherCustomLink-ICustomLinkSoap"> 
    <ARequest xsi:type="xsd:string"> 
    <?xml version="1.0" encoding="windows-1252"?> <EoCustomLinkRequestDateTime Type="TEoCustomLinkRequestDateTime"></EoCustomLinkRequestDateTime> 
    </ARequest> 
    </NS2:ExecuteRequest> 
    </SOAP-ENV:Body> 
    </SOAP-ENV:Envelope> 

皂XML请求但问题是让PARAM在标题(如的xmlns:NS1 ...)和body(如xmlns:NS2 ...)标签 使用我的脚本,我将NS1和NS2换成标头和正文后面的第一个标签。结果在<NS1:TAuthenticationHeader> ....和。 </NS2:ExecuteRequest>

我的PHP脚本:

<?php 

$wsdl_url = 'http://xxx.xxx.xxx.xxx:yyyy/wsdl/ICustomLinkSoap'; 
$location = 'http://xxx.xxx.xxx.xxx:yyyy/soap/ICustomLinkSoap'; 
$action = 'ExecuteRequest'; 
$version = SOAP_1_1; 
$one_way = 0; 


$soapClient = new SoapClient($wsdl_url, array(
    'cache_wsdl' => WSDL_CACHE_NONE, 
    'trace'   => true, 
    'encoding' => 'ISO-8859-1', 
    'exceptions' => true, 

)); 

$auth = (object)array(
     'UserName'=>'xxxx', 
     'Password'=>'yyyy' 
     ); 
$header = new SoapHeader($wsdl_url,'TAuthenticationHeader',$auth,false); 
$soapClient->__setSoapHeaders($header); 

$request1 = ' 
<ARequest> 
&lt;?xml version="1.0" encoding="windows-1252"?&gt; 

     &lt;EoCustomLinkRequestDateTime Type="TEoCustomLinkRequestDateTime" xsi:noNamespaceSchemaLocation="GdxEoStructures.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt; 

     &lt;/EoCustomLinkRequestDateTime&gt;</ARequest> 
'; 

$xmlVar = new SoapVar($request1, XSD_ANYXML); 

$result = $soapClient->__SoapCall(
    'ExecuteRequest', 
    array($xmlVar) 
); 

// show result in xml-file 
$f = fopen("./soap-request2.xml", "w"); 
xx = serialize($soapClient->__getLastRequest()); 
fwrite($f, $xx); 

?> 

结果:

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope 
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:ns1="urn:UCoSoapDispatcherCustomLink-ICustomLinkSoap" 
    xmlns:ns2="http://xxx.xxx.xxx.xxx:yyy/wsdl/ICustomLinkSoap" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 
    SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 

    <SOAP-ENV:Header> 
     <ns2:TAuthenticationHeader> 
      <UserName>xxxx</UserName> 
      <Password>yyyy</Password> 
     </ns2:TAuthenticationHeader> 
    </SOAP-ENV:Header> 

    <SOAP-ENV:Body> 
     <ns1:ExecuteRequest> 
      <ARequest> 
      &lt;?xml version="1.0" encoding="windows-1252"?&gt; 
     &lt;EoCustomLinkRequestDateTime Type="TEoCustomLinkRequestDateTime" xsi:noNamespaceSchemaLocation="GdxEoStructures.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt; 
     &lt;/EoCustomLinkRequestDateTime&gt; 
     </ARequest> 
     </ns1:ExecuteRequest> 
    </SOAP-ENV:Body> 

</SOAP-ENV:Envelope> 

请帮忙怎么办呢?

埃里克

回答

0

但问题是让PARAM在标题(如的xmlns:NS1 ...)和 体(如的xmlns:NS2 ...)标签用我的剧本,我得到NS1和NS2在标头和正文后的第一个标签中交换了 。结果在 ....和。

这不是一个问题,因为交换不仅元素的命名空间也是其在SOAP-ENV的头部定义:信封

你的第一个XML

xmlns:NS1="urn:UCoSoapDispatcherBase" 
xmlns:NS2="urn:UCoSoapDispatcherCustomLink-ICustomLinkSoap" 

比较与PHP产生

xmlns:ns1="urn:UCoSoapDispatcherCustomLink-ICustomLinkSoap" 
xmlns:ns2="http://xxx.xxx.xxx.xxx:yyy/wsdl/ICustomLinkSoap" 
相关问题