PHP SoapClient - How to Structure Soap Header

Related searches

Using SoapClient in PHP 5.3.28 would like to create a soap header that looks like:

  <ns:RequestParams Size="Large" Color="Blue" Brand="xyz">

If I construct the header like this:

    $params = array('RequestParams' => array('Size' => 'Large', 'Color' => 'Blue', 'Brand' => 'xyz');
    $header = new SoapHeader(NameSpace, 'RequestParams', $params);
    $client = new SoapClient(NULL, array("location" => "https://endpoint-url",
                                         "uri" => "http://namespace-uri",
                                         "soap_version" => SOAP_1_2, "trace" => 1));

    $result = $client->__soapCall(some soap call here);
    echo $client->__getLastRequest() . "\n";

The header I get is:


and I get a response from the server telling me it's an invalid header. I've searched around and there doesn't appear to be too much info on how PHP soapclient creates headers from data strctures. Any idea how I can get the header format I want using SoapClient? Any pointers appreciated.

use can you use an array for this

$parm = array(
    'properties' => array(
        'Size' => 'Large',
        'Color' => 'Blue',
        'Brand' => 'xyz'
    ),  );

will create this

<properties Size="Large" Color="Blue" Brand="xyz">

SoapHeader::SoapHeader - Manual, Here is an example of creating a nested header and including a parameter. $ client = new SoapClient(WSDL,array()); $auth = array( 'UserName'=>' USERNAME'� If you want to create an soap header wihtout namespace and without an item key value setup, you can use SoapVar To get this: <SOAP-ENV:Header> <IdentityHeader>

Couldn't find any straightforward way to create a header with params as attributes of one node. In the end this works, though not very pretty:

$client = new SoapClient(NULL, 
                         array('location' => $loc, 'uri' => $ns, 
                               'soap_version' => SOAP_1_2, 
                               'style' => SOAP_DOCUMENT));
$headerVar = new SoapVar('<ns1:RequestParams Size="Large" Color="Blue" Brand="xyz"/>',
$header = new SoapHeader($ns, 'RequestParams', $headerVar);
$result = $client->__soapCall('SomeFunc', array(...));

Thanks to Feroz for suggesting an answer, whitch btw works if you are sending parameters in __soapCall, just didn't work when creating a header.

Thanks also to cb for the solution:

SoapHeader - Manual, use can you use an array for this $parm = array( 'properties' => array( 'Size' => ' Large', 'Color' => 'Blue', 'Brand' => 'xyz' ), );. will create this 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

how about

$headers = 
           "Content-Type: text/xml; charset=utf-8",
           "Accept: text/xml",
           "Cache-Control: no-cache",
           "Pragma: no-cache",
           "SOAPAction:" . '"' . $soapAction . '"',
           "Content-length: " . strlen($xml)

PHP SoapClient - How to Structure Soap Header, An array of headers to be sent along with the SOAP request. output_headers $ client = new SoapClient(null, array('location' => "http://localhost/soap.php", It did return the backbone, but nothing within the objects that made up the structure. With a modern PHP version it is NOT necessary to add anything to the WSDL as the headers are part of the SOAP Envelope specification.. The user contributed example cited by Paul Dixon does not work simply because the header is not UserToken as written in the comment, the header is Security, so that’s is the name the class method should have.

SoapClient::__soapCall, Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java� Setting the boolean trace option enables use of the methods SoapClient->__getLastRequest, SoapClient->__getLastRequestHeaders, SoapClient->__getLastResponse and SoapClient->__getLastResponseHeaders. The exceptions option is a boolean value defining whether soap errors throw exceptions of type SoapFault .

XML Soap, As for the KeepAlive, if creating a new separate vhost for the soap api is not possible, you can add this to your existing vhost: BrowserMatch "^PHP-SOAP" nokeepalive where PHP-SOAP is the agent name of your soap client, if you dont know what agent name your client use, just checkout the access.log of your apache.

SOAP and PHP. SOAP is a protocol to exchange objects over http. It is used to implement apis and the data being exchanged is in xml format. Sometimes it might be required to modify the soap request to add custom http headers for example. Since SoapClient is a class, it can be extended and the request process can be modified.

  • Think I'll just go with this solution:…
  • Thanks feroz but the header I get with this is: <env:Header> <ns2:RequestParams> <item><key>RequestParams</key><value> <item><key>Size</key><value>Large</value></item> <item><key>Color</key><value>Blue</value></item> <item><key>LastName</key><value>xyz</value></item></value> </item> </ns2:RequestParams> </env:Header>