None of the examples really do it for me.
Note: you should NOT need to hard-code any XML.
Here is an example of creating a nested header and including a parameter.
$client = new SoapClient(WSDL,array());
$auth = array(
'UserName'=>'USERNAME',
'Password'=>'PASSWORD',
'SystemId'=> array('_'=>'DATA','Param'=>'PARAM'),
);
$header = new SoapHeader('NAMESPACE','Auth',$auth,false);
$client->__setSoapHeaders($header);
Gives the following header XML:
<SOAP-ENV:Header>
<ns1:Auth>
<ns1:SystemId Param="PARAM">DATA</ns1:SystemId>
<ns1:UserName>USERNAME</ns1:UserName>
<ns1:Password>PASSWORD</ns1:Password>
</ns1:Auth>
</SOAP-ENV:Header>
The SoapHeader class
(PHP 5 >= 5.0.1)
Introduction
Represents a SOAP header.
Class synopsis
SoapHeader
{
/* Methods */
__construct
( string
$namespace
, string $name
[, mixed $data
[, bool $mustunderstand
[, string $actor
]]] )
SoapHeader
( string
}$namespace
, string $name
[, mixed $data
[, bool $mustunderstand = false
[, string $actor
]]] )Table of Contents
- SoapHeader::__construct — SoapHeader constructor
- SoapHeader::SoapHeader — SoapHeader constructor
john at jtresponse dot co dot uk ¶
1 year ago
jstilow at mobileobjects dot de ¶
1 year ago
It cost me some time to figure out how to add a SoapHeader to a server response. For me the following solution works well enough:
<?php
class SoapService {
private $server = null;
public function __construct($server)
{
$this->server = $server;
}
public function soap($request) {
// do something useful
// These are the two "magic" lines:
$header = new SoapHeader("namespace", "name", new HeaderClass("possible some parameters"));
$this->soap_server->addSoapHeader($header);
// do more useful stuff
}
}
$soap_server = new SoapServer("./your.wsdl");
$soap_server->setClass("SoapService", $soap_server);
$soap_server->handle();
?>
See also:
https://bugs.php.net/bug.php?id=32410
