SOAP
在线手册:中文 英文
PHP手册

The SoapHeader class

(No version information available, might only be in SVN)

简介

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
在线手册:中文 英文
PHP手册
PHP手册 - N: The SoapHeader class

用户评论:

john at jtresponse dot co dot uk (13-Mar-2012 09:30)

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 (10-Oct-2011 03:03)

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