1

I'm getting an error from a SOAP server built on Java when I use PHP's SOAP library because the name of the envelope is prefixed with SOAP-ENV. The web service requires s:

What I'm sending:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>...</SOAP-ENV:Header>
<SOAP-ENV:Body>...</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

What the web service requires:

<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>...</s:Header>
<s:Body>...</s:Body>
</s:Envelope>

I've been through php.net'S SOAP library documentation already. Nothing there seems to touch on this part.

And yes, it does matter to this web service whether it's prefixed with SOAP-ENV: or s:

Here's what is generating the current style of XML:

$client = new SoapClient($url, array(
    'soap_version' => SOAP_1_1,
    'trace' => 1,
    'use' => SOAP_LITERAL)
);

$result = $client->$method($dataObject);

Any help would be greatly appreciated.

  • https://stackoverflow.com/questions/41610597/php-soap-client-how-to-change-namespace-prefix suggests it isn't possible (although they do ask specifically about the *soup client*) – Nigel Ren Oct 01 '19 at 16:02
  • https://stackoverflow.com/questions/8650580/change-soap-prefixes-in-php/8727015#8727015 gives a way of extending the SoapClient class to be able to do this. Have a read see if it helps. – Nigel Ren Oct 01 '19 at 16:07
  • @NigelRen - yes, soup clients. Much more appetizing than soap. I'm going to try and extend the SoapClient class like in the second suggestion and see if that does the trick. I'll post results. – Brent Miller Oct 01 '19 at 18:32

1 Answers1

0

This solution worked for me.

class mySoapClient extends \SoapClient
{
    public function __doRequest($request, $location, $action, $version, $one_way = 0)
    {
        $request = str_replace(
            array('SOAP-ENV', 'other-text'),
            array('s', 'new-other-text'),
            $request
        );

        return parent::__doRequest($request, $location, $action, $version, $one_way);
    }
}

The array allows you to trigger a series of changes.