PHP Doku:: Setzt SOAP-Header für nachfolgende Aufrufe - soapclient.setsoapheaders.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzWeb ServicesSOAPThe SoapClient classSoapClient::__setSoapHeaders

Ein Service von Reinhard Neidl - Webprogrammierung.

The SoapClient class

<<SoapClient::__setLocation

SoapClient::__soapCall>>

SoapClient::__setSoapHeaders

(PHP 5 >= 5.0.5)

SoapClient::__setSoapHeadersSetzt SOAP-Header für nachfolgende Aufrufe

Beschreibung

public bool SoapClient::__setSoapHeaders ([ mixed $soapheaders ] )

Legt die Header fest, die mit den nächsten SOAP-Requests gesendet werden.

Hinweis:

Der Aufruf dieser Methode ersetzt alle vorherigen Werte.

Parameter-Liste

soapheaders

Die zu setzenden Header. Dies kann ein SoapHeader-Objekt oder ein Array von SoapHeader-Objekten sein. Ist der Parameter nicht angegeben oder hat er den Wert NULL, werden die Header gelöscht.

Rückgabewerte

Gibt bei Erfolg TRUE zurück. Im Fehlerfall wird FALSE zurückgegeben.

Beispiele

Beispiel #1 SoapClient::__setSoapHeaders()-Beispiel

<?php

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

$client->__setSoapHeaders($header);

$client->__soapCall("echoVoid"null);
?>

Beispiel #2 Mehrfachheader setzen

<?php

$client 
= new SoapClient(null, array('location' => "http://localhost/soap.php",
                                     
'uri'      => "http://test-uri/"));
$headers = array();

$headers[] = new SoapHeader('http://soapinterop.org/echoheader/',
                            
'echoMeStringRequest',
                            
'hello world');

$headers[] = new SoapHeader('http://soapinterop.org/echoheader/',
                            
'echoMeStringRequest',
                            
'hello world again');

$client->__setSoapHeaders($headers);

$client->__soapCall("echoVoid"null);
?>


4 BenutzerBeiträge:
- Beiträge aktualisieren...
mlconnor at yahoo dot com
11.11.2010 22:28
Does anyone know how to get the response headers?  The getLastResponseHeader returns a string response, not the complex object I was expecting...
peamik1953 at NOSPAM dot btinternet dot com
12.07.2010 20:06
You cannot add an additional header. If you want two headers, and one already exists, first delete it with $client->__setSoapHeaders(NULL). Then issue $client->__setSoapHeaders($headers) where $headers is an array of soapHeader() objects.
kedar dot purohit @ mavs dot uta dot edu
10.09.2009 21:58
To create complex SOAP Headers, you can do something like this:

Required SOAP Header:

<soap:Header>
    <RequestorCredentials xmlns="http://namespace.example.com/">
      <Token>string</Token>
      <Version>string</Version>
      <MerchantID>string</MerchantID>
      <UserCredentials>
        <UserID>string</UserID>
        <Password>string</Password>
      </UserCredentials>
    </RequestorCredentials>
</soap:Header>

Corresponding PHP code:

<?php

$ns
= 'http://namespace.example.com/'; //Namespace of the WS.

//Body of the Soap Header.
$headerbody = array('Token' => $someToken,
                   
'Version' => $someVersion,
                   
'MerchantID'=>$someMerchantId,
                     
'UserCredentials'=>array('UserID'=>$UserID,
                                            
'Password'=>$Pwd));

//Create Soap Header.       
$header = new SOAPHeader($ns, 'RequestorCredentials', $headerbody);       
       
//set the Headers of Soap Client.
$soap_client->__setSoapHeaders($header);

?>
jayrajput at gmail dot com
30.03.2009 23:07
With multiple SOAP headers, when using SoapVar for creation of SoapHeader the PHP code just terminates (command terminated). I am not sure if that is a bug.

Without the SOAPVar the code worked fine for me

There are different way to creart SoapHeader I was using SoapVar and the code was not working. I am still a novice with this SOAP stuff.

Tried using normal strings and it worked fine. SoapHeader can take SoapVar or string as the third argument.

my code:

<?php
// first soap header.
$var = new SoapVar($header, XSD_ANYXML);
$soapHeader = new SoapHeader(NAME_SPACE, "Security", $var);
// second soap header.
$var2 = new SoapVar($header2, XSD_ANYXML);
$soapHeader2 = new SoapHeader(DIFF_NAME_SPACE, "ID", $var2);

$client = new SoapClient($wsdl, array("location" => $location));

$headers = array();
$headers[] = $soapHeader;
$headers[] = $soapHeader2;

// Here my code was just terminating.
$client->__setSoapHeaders($headers);
?>



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)