Page 1 of 1

how to write a soapHeader by PHP?

Posted: Sun Feb 22, 2009 8:21 am
by shiwudao
hi, I have a soap request as follows:
<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/ ... xt-1.0.xsd" xmlns:myns="myns.xsd">

<SOAP-ENV:Header>
<wsse:Security SOAP-ENV:mustUnderstand="true">
<myns:MySessionKeyToken>
<myns:SessionKey>xxxxxxxxxxxxxxx</myns:SessionKey>
<myns:MySessionKeyToken>
</wsse:Security>
</SOAP-ENV:Header>

<SOAP-ENV:Body><myns:MyMethod/></SOAP-ENV:Body></SOAP-ENV:Envelope>


Question here is how to use PHP to write the soapHeader?
I tried the code like:
$key="xxxxxxxxxxxxxxx";
$keytag = new SoapVar($key, XSD_STRING, "SessionKey", "myns.xsd");
$token = new SoapVar($keytag, SOAP_ENC_OBJECT,"MySessionKeyToken","myns.xsd");
$header = new SoapHeader("http://docs.oasis-open.org/wss/2004/01/ ... xt-1.0.xsd", "Security", $token, true);

$resutl= $client->__soapCall("MyMethod", array(null), null, $header);

But I failed with error "Referenced security token could not be retrieved"

Looks like I did not set the header contents correctly?
Anybody can teach me how to write the soapHeader? thank you