Jump to content

PHP-SOAP with non-standard Headers


senyahnoj

Recommended Posts

I'm trying to connect to a SOAP API using PHP-SOAP. The problem is that the API is not adhering to the SOAP standard entirely.

 

The SOAP Headers XML which the SOAP client needs to generate are as follows:

 

<SOAP-ENV:Header>
   <TargetVolume>foo</TargetVolume>
</SOAP-ENV:Header>

 

The problem is that the PHP SoapHeader class requires namespaces to be set for SOAP Header child elements (as in the standard). My code goes:

 

$ns = 'http://some.namespace.com';
$header = new SoapHeader($ns,'TargetVolume','foo');
$soapClient->__setHeaders($header);

 

which produces:

 

<SOAP-ENV:Header>
   <ns1:TargetVolume>foo</ns1:TargetVolume>
</SOAP-ENV:Header>

 

Unfortunately

 

1. the SOAP API I'm using doesn't accept the ns1 namespace - or any namespace :(

2. The SoapHeader constructor does not accept NULL as its first parameter

3. I can't change the API!

 

This is not a bug in PHP. See the discussion at http://bugs.php.net/bug.php?id=31755 which details that it's invalid in SOAP to use a namespace here.

 

I am stuck in between a rock and a hard place with finding a work-around for this problem: to somehow get PHP-SOAP to send the required non-standard header to the API.

 

Can anybody help?

Link to comment
https://forums.phpfreaks.com/topic/229564-php-soap-with-non-standard-headers/
Share on other sites

Solved - someone on another forum kindly gave me a work-around:

 

class XSoapClient extends SoapClient
{
    public function __doRequest($request, $location, $action, $version, $one_way = null)
    {
        $request = preg_replace('/ns1:TargetVolume/','TargetVolume',$request, -1);  
        return parent::__doRequest($request, $location, $action, $version, $one_way);
    }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.