1

My problem is with SOAP Header in PHP. I can not set mustUnderstand attribute to soap request. Could you please help me for my code?

$root = new SimpleXMLElement('<header/>');

$security = $root->addChild('wsse:Security', null, $ns_wsse);
$security->addAttribute('soapenv:mustUnderstand', true);

$usernameToken = $security->addChild('wsse:UsernameToken', null, $ns_wsse);
$usernameToken->addChild('wsse:Username', $username, $ns_wsse);
$usernameToken->addChild('wsse:Password', $password, $ns_wsse)->addAttribute('Type', $password_type);
$usernameToken->addChild('wsse:Nonce', $encoded_nonce, $ns_wsse)->addAttribute('EncodingType', $encoding_type);
$usernameToken->addChild('wsu:Created', $tm_created, $ns_wsu);

// Recovering XML value from that object
$root->registerXPathNamespace('wsse', $ns_wsse);

Header('Content-type: text/xml');
$full = $root->xpath('/header/wsse:Security');
$auth = $full[0]->asXML();
echo $auth;

Output:

<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" mustUnderstand="1">
<wsse:UsernameToken>
<wsse:Username></wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-usernametoken-profile-1.0#PasswordText"></wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">MTk5Njg4NjYzOQ==</wsse:Nonce>
<wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2018-08-13T10:57:52Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>

I want to add soapenv:mustUnderstand="1" attribute instead of mustUnderstand="1". Other attributes are added but "soapenv:" can not added, so I can not receive data from web service. It gives error.

expected header:

 <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">

Thanks in advance.

Ozzlem
  • 29
  • 4

0 Answers0