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

search for in the

SoapClient::__soapCall> <SoapClient::__setLocation
Last updated: Fri, 14 Aug 2009

view this page in

SoapClient::__setSoapHeaders

(PHP 5 >= 5.0.5)

SoapClient::__setSoapHeadersAjoute un entête SOAP pour les requêtes suivantes

Description

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

Définit un entête à utiliser dans les requêtes SOAP.

Note: Cette méthode va remplacer la valeur précédente.

Liste de paramètres

soapheaders

L'entête à configurer. S'il n'est pas spécifié, tous les entêtes seront détruits.

Valeurs de retour

Cette fonction retourne TRUE en cas de succès, FALSE en cas d'échec.

Exemples

Exemple #1 Exemple avec SoapClient::__setSoapHeaders()

<?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);
?>

Exemple #2 Configuration d'entêtes multiples pour SOAP

<?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);
?>



add a note add a note User Contributed Notes
SoapClient::__setSoapHeaders
kedar dot purohit @ mavs dot uta dot edu
10-Sep-2009 07: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-Mar-2009 09: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);
?>

SoapClient::__soapCall> <SoapClient::__setLocation
Last updated: Fri, 14 Aug 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites