Monday, January 21, 2008

Why We need a Timestamp in a SOAP message

A common concern in message-oriented systems relates to the timeliness of data. If the data is too old, it may get thrown out. If two contradicting messages arrive, the related timestamps may be used to decide which message gets executed and which one is ignored. To handle the time-related issues that showed up in WS-Security the wsu:Timestamp element, along with a few helper elements, was defined.

By knowing the creation and expiration time, a receiver can decide if the data is new enough for its own use or if the data has become so stale that the message should be discarded. Following elements are used in a Timestamp.

wsu:Created: Contains the time that the message was created.
wsu:Expires: Set by a sender or intermediary, this identifies when the message expires.

Adding a timestamp to your SOAP message using Web Services framework for PHP is really easy.You only need to add following lines to your PHP script.

/*sec array is the array in which you specify security options*/

$sec_array = array("includeTimeStamp" => TRUE );

/*The valid time period of the message in seconds.*/
$sec_token = new WSSecurityToken(array("ttl" => 300));

No comments: