Friday, February 1, 2008

Creating a custom header using an xml string

Sometimes it is necessary to send data to the service using headers. When doing so, WSF/PHP supports two ways of doing this. It accepts recursive WSHeader arrays in its constructor. Also it is possible to put an xml string directly to the WSHeader constructor.

WSHeader constructor signature is as follows.
WSHeader:__construct(array options);

options is an associative array with the following values.
"ns"=> Namespace of the header
"prefix"=> If you want to associate a profix with the namespace, this can be used to set the prefix
"name"=> Localname of the header element
"data"=> string Array of WSHeader objects
"mustUnderstand" => Bool
"role" => int

So when sending a complex header element, one can use the array of WSHeader objects but sometimes this may get quite complex.

Instead it is now possible to pass the xml string of the header element's child to the "data".
$child = <<< XML

$header = new WSHeader(array("name"=>"product", "ns"=>'', "data"=>$child));

How ever this only supports adding a single child element to the header. So hope to extend this to pass an array as well.

No comments:

Post a Comment