senyahnoj Posted March 4, 2011 Share Posted March 4, 2011 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 More sharing options...
senyahnoj Posted March 7, 2011 Author Share Posted March 7, 2011 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 https://forums.phpfreaks.com/topic/229564-php-soap-with-non-standard-headers/#findComment-1183937 Share on other sites More sharing options...
beegro Posted March 7, 2011 Share Posted March 7, 2011 Thanks for posting that solution. I've had a similar problem previously and my fix was much less elegant than this. Link to comment https://forums.phpfreaks.com/topic/229564-php-soap-with-non-standard-headers/#findComment-1184057 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.