0

In PHP I need to create a soap-xml request like

   <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>

But the problem is to get param in the header (like xmlns:NS1...) and body (like xmlns:NS2...) tags With my script I get NS1 and NS2 swapped in the first tag after header and body. results in <NS1:TAuthenticationHeader> .... and . </NS2:ExecuteRequest>

My php script:

<?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);

?>

Result:

    <?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>

Please help to how to do so?

Eric

1 Answers1

0

But the problem is to get param in the header (like xmlns:NS1...) and body (like xmlns:NS2...) tags With my script I get NS1 and NS2 swapped in the first tag after header and body. results in .... and .

It's not a problem, because swapped not only namespaces of elements but also its definitions at the head of SOAP-ENV:Envelope

Your first xml

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

Compare with generated by php

xmlns:ns1="urn:UCoSoapDispatcherCustomLink-ICustomLinkSoap" 
xmlns:ns2="http://xxx.xxx.xxx.xxx:yyy/wsdl/ICustomLinkSoap" 
alexander.polomodov
  • 5,396
  • 14
  • 39
  • 46