PHP: SoapHeader->__construct() - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

SoapParam->__construct() SoapFault->__construct()

Last updated: Sat, 27 Jan 2007

view this page in

# SoapHeader->__construct()

(no version information, might be only in CVS)

SoapHeader->__construct() -- SoapHeader constructor

## Описание

class SoapHeader {
__construct ( string namespace, string name [, mixed data [, bool mustUnderstand [, mixed actor]]] )
}

Constructs a new SoapHeader object.

## Список параметров

`namespace`

  The namespace of the SOAP header element.

`name`

  The name of the SOAP header element.

`data`

  A SOAP header's content. It can be a PHP value or a SoapVar object.

`mustUnderstand`

  Value of the `mustUnderstand` attribute of the SOAP header element.

`actor`

  Value of the `actor` attribute of the SOAP header element.

## Примеры

Пример 1. Some examples

`<?php
$client = new SoapClient(null, array('location' => "http://localhost/soap.php",
'uri' => "http://test-uri/"));
$client->__call("echoVoid", null, null,
new SoapHeader('http://soapinterop.org/echoheader/',
'echoMeStringRequest',
'hello world'));
?>`

## Смотрите также

SoapClient->__soapCall()
SoapVar->__construct()
SoapParam->__construct()

add a note User Contributed Notes
SoapHeader->__construct()
harlan at plauditdesign dot com
15-Mar-2006 11:04
`Here is a way to get headers on the server side. It will fill up an assoc with all headers in a namespace. In its current state, it only handles text content; but each header is expanded to a DOMNode, so you can do whatever you wish to parse custom types.
In my case this method is useful because I want to pass PHPSESSID in a SOAP header, and I need to set it before I even call SoapServer::handle().
//
// READ SOAP HEADERS, STOP READING AT SOAPENV:BODY ELEMENT
//
$xml = new XmlReader();
$xml->XML( $HTTP_RAW_POST_DATA );
$shoppingCartHeaders = array();
while( $xml->read() ) {
if( $xml->namespaceURI == "urn:com.plauditdesign.shoppingcart.client.headers#"
&& $xml->nodeType == XMLReader::ELEMENT ) {
$headerNode = $xml->expand();
$shoppingCartHeaders[ $xml->localName ] = $headerNode->textContent;
} elseif( $xml->namespaceURI == "http://schemas.xmlsoap.org/soap/envelope/"
&& $xml->nodeType == XMLReader::ELEMENT
&& $xml->localName == "Body" ) {
$xml->close();
}
}
...
if( isset( $shoppingCartHeaders["sessionId"] ) ) {
session_id( $shoppingCartHeaders["sessionId"] );
}
...
$server->setPersistence( SOAP_PERSISTENCE_SESSION );
$server->handle();`
jared DOT kuolt at gmail dot com
28-Oct-2005 09:57
`To build the authentication headers like below FOR WSDL:
**NOTE** I cannot find documentation on the __setSoapHeaders() method, though it does work in 5.0.4
<?php
class MySoapClass
{
function __construct(){
// Blah blah blah
$this->soap = new SoapClient($this->foo, $this->bar);
}
// Build that header!
private function build_auth_header(){
// Build an object with parameters
$auth->username = $this->username;
$auth->password = $this->password;
$authvalues = new SoapVar($auth, SOAP_ENC_OBJECT);
$header = new SoapHeader($this->name_space, "Authentication", // Rename this to the tag you need
$authvalues, false);
$this->soap->__setSoapHeaders(array($header));
}
// Wrapper so we can build auth header first
public function MySoapFunction($params){
$this->build_auth_header();
$this->soap->MySoapFunction($params);
}
}
?>`
mobi at delfnet dot pl
31-May-2005 12:24
`In botoom code is bug.
is:
// create authentication header values
$authvalues=new SoapVar($auth,SOAP_ENC_OBJECT,'authenticate');
should be:
// create authentication header values
$authvalues=new SoapVar($auth,SOAP_ENC_OBJECT);`
clewis at myfonts dot com
09-Feb-2005 08:52
`If you are using WSDL to define your SOAP Headers, note that PHP's SoapServer class will not process incoming headers unless the <message> and <part> names are identical for the header methods.
Define a SOAP header function like this in WSDL:
<!-- replace "tns:" with your own namespace abbreviation -->
<!-- define method arguments using a complexType -->
<xsd:complexType name="HeaderMethodArgs">
<xsd:all>
<xsd:element ... name="arg1"/>
<xsd:element ... name="arg2"/>
</xsd:all>
</xsd:complexType>
<!-- define method message with single part -->
<message name='headerMethodName'>
<part name='headerMethodName' type='tns:HeaderMethodArgs'/>
</message>
<!-- add header tag to operations that use this header -->
<operation name='someBodyMethod'>
...
<input>
<soap:body .../>
<soap:header
...
message='tns:headerMethodName'
part='headerMethodName'
/>
</input>
<output>...</output>
</operation>`
php dot net at sowen dot de
18-Jan-2005 03:02
`If you are trying to create a header like this:
<SOAP-ENV:Header>
<ns2:authenticate SOAP-ENV:actor="http://schemas.xmlsoap.org/soap/actor/next">
<username>myuser</username>
<password>secret</password>
</ns2:authenticate>
</SOAP-ENV:Header>
Try to use a class to create Header-vars:
class authentication_header {
private $username;
private $password;
public function __construct($username,$password) {
$this->username=$username;
$this->password=$password;
}
}
In your soap client program:
// generate new object
$auth=new authentication_header('myuser','secret');
// create authentication header values
$authvalues=new SoapVar($auth,SOAP_ENC_OBJECT,'authenticate');
// generate header
$header=new SoapHeader("myURN",
"authenticate",
$authvalues,
false,
"http://schemas.xmlsoap.org/soap/actor/next");
And do the request like this (non-WSDL version):
$client->__call('function', $params, null, $header);
Have fun,
Nils Sowen`
add a note
SoapParam->__construct() SoapFault->__construct()

Last updated: Sat, 27 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 10:36:09 2007 PST