SOAP
在线手册:中文  英文

The SoapHeader class

(PHP 5 >= 5.0.1)

简介

Represents a SOAP header.

类摘要

SoapHeader {
/* 方法 */
__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


SOAP
在线手册:中文  英文

用户评论:

john at jtresponse dot co dot uk (2012-03-13 13:30:22)

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>

jstilow at mobileobjects dot de (2011-10-10 07:03:17)

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

易百教程