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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.