PHP SoapClient SoapParam and SoapVar

Petyo Tsonev Source

Hello i have strange issue if i can call it that way... I am trying to figure out how to send "semi-escaped" xml string as parameter which is called "xml" to Soap Web Service.

The Schema i need generated is this one:

<?xml version="1.0" encoding="utf-16"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
    <AuthHeader xmlns="https://url.temp/">
        <UserName>Test</UserName>
        <Password>Test</Password>
    </AuthHeader>
</soap:Header>
<soap:Body>
    <CreateTerminalSession xmlns="https://url.temp/">
        <xml>&lt;?xml version="1.0" encoding="utf-16"?&gt;
            &lt;Request&gt;
            &lt;ServiceLogin&gt;
            &lt;ServiceUserName&gt;Test&lt;/ServiceUserName&gt;
            &lt;ServicePassword&gt;Test&lt;/ServicePassword&gt;
            &lt;MCSAccountID&gt;1&lt;/MCSAccountID&gt;
            &lt;/ServiceLogin&gt;
            &lt;SaleInformation&gt;
            &lt;DeviceID&gt;2LK1234&lt;/DeviceID&gt;
            &lt;Type&gt;Sale&lt;/Type&gt;
            &lt;Amount&gt;1.00&lt;/Amount&gt;
            &lt;TipAmount&gt;-1&lt;/TipAmount&gt;
            &lt;AutoTransmit&gt;1&lt;/AutoTransmit&gt;
            &lt;GatewayID&gt;1&lt;/GatewayID&gt;
            &lt;/SaleInformation&gt;
            &lt;/Request&gt;</xml>
    </CreateTerminalSession>
</soap:Body>
</soap:Envelope>

The schema which i am generating using this code is

"""
<?xml version="1.0" encoding="UTF-8"?>\n
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https:/url.temp/"><SOAP-ENV:Header><ns1:AuthHeader><ns1:UserN ▶
&amp;lt;Request&amp;gt;\n
  &amp;lt;ServiceLogin&amp;gt;\n
    &amp;lt;ServiceUserName&amp;gt;userxxx&amp;lt;/ServiceUserName&amp;gt;\n
    &amp;lt;ServicePassword&amp;gt;xxx&amp;lt;/ServicePassword&amp;gt;\n
    &amp;lt;MSCSAccountID&amp;gt;xxx8&amp;lt;/MSCSAccountID&amp;gt;\n
  &amp;lt;/ServiceLogin&amp;gt;\n
  &amp;lt;SaleInformation&amp;gt;\n
    &amp;lt;DeviceID&amp;gt;2LK1234&amp;lt;/DeviceID&amp;gt;\n
    &amp;lt;Type&amp;gt;Sale&amp;lt;/Type&amp;gt;\n
    &amp;lt;Amount&amp;gt;1.00&amp;lt;/Amount&amp;gt;\n
    &amp;lt;TipAmount&amp;gt;-1&amp;lt;/TipAmount&amp;gt;\n
    &amp;lt;AutoTransmit&amp;gt;1&amp;lt;/AutoTransmit&amp;gt;\n
    &amp;lt;GatewayID&amp;gt;1&amp;lt;/GatewayID&amp;gt;\n
  &amp;lt;/SaleInformation&amp;gt;\n
&amp;lt;/Request&amp;gt;\n
</ns1:xml></ns1:CreateTerminalSession></SOAP-ENV:Body></SOAP-ENV:Envelope>\n
"""

The code used to generate the above response:

    $response = $client->__soapCall('CreateTerminalSession', [['xml' => $correctString]]);

The error here is that XmlWriter escapes "&" with &amp which is invalid in my case the webservice refuse it in this format...

The solution i tried was this:

$params = array(
           new \SoapParam(new \SoapVar($correctString, XSD_ANYXML), 'xml')
        );
            $response = $client->__soapCall('CreateTerminalSession', $params);

Which led to this response. String is properly escaped as webservice expects it, but there is no command name "CreateTerminalSession" neither param name "":

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://temp.url/">
<SOAP-ENV:Header>
    <ns1:AuthHeader>
        <ns1:UserName>testurs</ns1:UserName>
        <ns1:Password>testww</ns1:Password>
    </ns1:AuthHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
    &lt;Request&gt;
    &lt;ServiceLogin&gt;
    &lt;ServiceUserName&gt;paramservice&lt;/ServiceUserName&gt;
    &lt;ServicePassword&gt;parampass&lt;/ServicePassword&gt;
    &lt;MSCSAccountID&gt;paramsscsa&lt;/MSCSAccountID&gt;
    &lt;/ServiceLogin&gt;
    &lt;SaleInformation&gt;
    &lt;DeviceID&gt;2LK1234&lt;/DeviceID&gt;
    &lt;Type&gt;Sale&lt;/Type&gt;
    &lt;Amount&gt;1.00&lt;/Amount&gt;
    &lt;TipAmount&gt;-1&lt;/TipAmount&gt;
    &lt;AutoTransmit&gt;1&lt;/AutoTransmit&gt;
    &lt;GatewayID&gt;1&lt;/GatewayID&gt;
    &lt;/SaleInformation&gt;
    &lt;/Request&gt;
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Which leads to this error from the server

Server was unable to process request. ---> Value cannot be null.\n
    Parameter name: s

So my question is how can i make this body which is properly escaped to have the command name and the param name in my case "CreateTerminalSession" and "xml". Any help will be really appreciate. Thanks in advance

phpxmlsoapxsdsoap-client

Answers

comments powered by Disqus