2016-03-04 91 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" 
相關問題