May4
In my previous post I outlined a way of providing server-side user session state to a DHTML UI using native Java or .NET sessions. In this post I want to show another option: a web service-based solution.
As part of the WebDaptive AJAX framework, QAT offers a web service for both Java and .NET that mimics the main aspects of user sessions, including the generation of unique, hard-to-predict ids and customizable timeout of idle sessions. You can create and discard session objects, store, retrieve and delete key-value pairs via web service calls. The session id can be passed to other application components so they can access the session too.
The web service session offers some unique advantages that are hard to duplicate with a traditional session object: If you pass the session id in requests or use a well-known id, any webservice-enabled technology can use that session. Your UI could tell a .NET application to store data in the session and later call a CICS web service or maybe another .NET application running with a different context, which then could read that data straight from the same session. If you think this requirement sounds far-fetched, consider this: You have a CA Gen web application with an UI that meets 90% of your users’ needs. For the remaining 10% of functionality, you would really like to offer a richer and more dynamic UI like a spread-sheet-like grid, something that can only be offered by non-Gen code. Depending on the complexity of the task, you may easily end up with code that uses several separate Java or .NET session objects that cannot be shared. A web service-based session can bridge this gap.
Using the WebDaptive Communication client, calling the session service (or any other web service) is as simple as this:
Step 1 – Retrieve a new session id:
This is useful if you want the security of unique, hard-to-guess identifiers. Alternatively, you can skip this step and use a session id of your choice.
var url = "http://localhost/WDSessService/WDSessionService.asmx";
// create new WebDaptive Communication client
var wdc = new WDClient();
// whether the calls are asynchronous
var async = true;
// will hold the session id
var sessionId;
// retrieve new session id
wdc.invokeSOAP(url, "GetNewSessionID", "GetNewSessionIDResult",
new WDRequestParameters(), async, function(result1, xml1, resultStatus1){
// callback functionality
sessionId = result1;
});
Step 2 – Store data in the session:
// use the session id
// create a parameter object and add all call parameters
var pl = new WDRequestParameters();
pl.add("sID", sessionId);
pl.add("sKey", "KEY");
pl.add("sValue", "SAMPLE DATA");
wdc.invokeSOAP(url, "SetSessionString", "SetSessionStringResult",
pl, async, function(result, xml, resultStatus){
// callback handler functionality here
sessionId = result;
});
Step 3 – Retrieve data from the session:
// use the session id
// create a parameter object and add all call parameters
var pl = new WDRequestParameters();
pl.add("sID", sessionId);
pl.add("sKey", "KEY");
wdc.invokeSOAP(url, "SetSessionString", "SetSessionStringResult",
pl, async, function(result, xml, resultStatus){
// callback handler functionality here
alert("The value of 'KEY' is '" + result + "'");
});
In .NET or Java, you will need to use the mechanisms of your web service stack to call the session service. QAT also provides custom functions that enable access from within Gen applications. Of course, there is additional overhead involved if you use the session service from within Java or .NET compared to using their native session objects but this overhead may be well worth it if you need to share data across context boundaries.
Bottom line – the WebDaptive Session service offers a web service-based session solution that is very flexible and can even benefit server-side technologies with native session handling because of its ability to share data with other technologies.
- Anke