How to generate Soap request using this xml in PHP?



I'm tired of trying to send a request with SOAP that using WS-secutrity. This is xml envelope example:



<s:Envelope xmlns:s="http://ift.tt/18hkEkn" xmlns:a="http://ift.tt/HKXHai"
xmlns:u="http://ift.tt/Hm2joJ">
<s:Header>
<a:Action s:mustUnderstand="1">http://ift.tt/1fncaaa;
<a:MessageID>urn:uuid:b8337de1-9cd0-42c6-a8ab-af440666cf2f</a:MessageID>
<a:ReplyTo>
<a:Address>http://ift.tt/1n9GFdN;
</a:ReplyTo>
<a:To s:mustUnderstand="1">http://ift.tt/1517cTA;
<o:Security s:mustUnderstand="1"
xmlns:o="http://ift.tt/LRW8Ij">
<u:Timestamp u:Id="_0">
<u:Created>2014-12-18T16:57:39.229Z</u:Created>
<u:Expires>2014-12-18T17:02:39.229Z</u:Expires>
</u:Timestamp>
<o:UsernameToken u:Id="uuid-66a9fd12-5846-41a5-8250-17abe6fb1806-11">
<o:Username>USERNAMEXXXXXXXX</o:Username>
<o:Password
Type="http://ift.tt/1aTA7XU">
PASSWORDXXXXXXXX
</o:Password>
</o:UsernameToken>
</o:Security>
</s:Header>
<s:Body>
<t:RequestSecurityToken xmlns:t="http://ift.tt/1iRriz0">
<t:TokenType>http://ift.tt/1lrsICB;
<t:RequestType>http://ift.tt/1vg7C0U;
<t:Entropy>
<t:BinarySecret u:Id="uuid-dda9572f-36f1-49c1-a0a5-24441199baf0-3"
Type="http://ift.tt/1lrsGuv">
dfsRtUdCmaNSea66xeIngWNudOhg7HCSWDDLAZNP3Ss=
</t:BinarySecret>
</t:Entropy>
<t:KeySize>256</t:KeySize>
</t:RequestSecurityToken>
</s:Body>
</s:Envelope>


I tried use WS-Security for PHP SoapClient and correcting $xml at generateWSSecurityHeader()



$timestamp = time();
$timestamp_created = gmdate('Y-m-d\TH:i:s\Z', $timestamp);

$timestamp_expire = gmdate('Y-m-d\TH:i:s\Z', $timestamp + 300);
//$token_uuid = $this->createID();
$token_uuid = "wdwd";

$xml = '
<u:Timestamp u:Id="_0">
<u:Created>'.$timestamp_created.'</u:Created>
<u:Expires>'.$timestamp_expire.'</u:Expires>
</u:Timestamp>
<o:UsernameToken u:Id="'.$token_uuid.'">
<o:Username>'.$this->username.'</o:Username>
<o:Password
Type="http://ift.tt/1aTA7XU">
'.$this->password.'
</o:Password>
</o:UsernameToken>
';


but got an error:



Fatal error: Uncaught SoapFault exception: [HTTP] Bad Request in C:\xampp\..\ws-client.php:58 Stack trace: #0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'https://myairop...', 'http://schemas....', 2, 0)


Soap


No comments:

Post a Comment