Using SoapClient in PHP 5.3.28 would like to create a soap header that looks like:
<soap:Header>
<ns:RequestParams Size="Large" Color="Blue" Brand="xyz">
</soap:Header>
If I construct the header like this:
$params = array('RequestParams' => array('Size' => 'Large', 'Color' => 'Blue', 'Brand' => 'xyz');
$header = new SoapHeader(NameSpace, 'RequestParams', $params);
$client = new SoapClient(NULL, array("location" => "https://endpoint-url",
"uri" => "http://namespace-uri",
"soap_version" => SOAP_1_2, "trace" => 1));
$client->__setSoapHeaders($header);
$result = $client->__soapCall(some soap call here);
echo $client->__getLastRequest() . "\n";
The header I get is:
<env:Header>
<ns2:RequestParams>
<item><key>RequestParams</key><value>
<item><key>Size</key><value>Large</value></item>
<item><key>Color</key><value>Blue</value></item>
<item><key>LastName</key><value>xyz</value></item></value>
</item>
</ns2:RequestParams>
</env:Header>
and I get a response from the server telling me it's an invalid header. I've searched around and there doesn't appear to be too much info on how PHP soapclient creates headers from data strctures. Any idea how I can get the header format I want using SoapClient? Any pointers appreciated.
how about
Couldn't find any straightforward way to create a header with params as attributes of one node. In the end this works, though not very pretty:
Thanks to Feroz for suggesting an answer, whitch btw works if you are sending parameters in __soapCall, just didn't work when creating a header.
Thanks also to cb for the solution: http://www.php.net/manual/en/soapvar.soapvar.php#91961
use can you use an array for this
will create this