Dealing with SOAP headers with WSF/PHP

There is a WSHeader class in WSF/PHP, using which you can set headers in the outgoing SOAP message. You can pass the array of SOAP headers to the WSMessage constructor as a parameter.

 

    $header = new WSHeader(array( "ns" => "http://test.org",
                                  "name" => "visitor",
                                  "data" => "Simon"));    

    $message = new WSMessage($requestPayloadString, array("inputHeaders" => array($header)));
    $client = new WSClient(array("to" => "http://localhost/tutorial/headers/service.php"));
    $response = $client->request($message);

The above code adds a header with the following XML to the outgoing SOAP message:

<ns0:visitor xmlns:ns0="http://test.org">Simon</ns0:visitor>

Comments