Maintaining Session State
Our final topic is the maintenance
of session state. As you may recall from Chapter 4, each deployed SOAP service has an associated
Scope
property. Each time a service is invoked,
the rpcrouter
servlet will invoke the remote
service object. The Scope
property defines the
lifetime of this remote object.
- Request
Indicates that the object will exist during the lifetime of one SOAP request/response cycle
- Session
Indicates that the
rpcrouter
will instantiate one object per client, and will maintain these objects across multiple request/response conversations- Application
Indicates that only one object is instantiated, and this one object will process all incoming requests
To make the Scope
property more concrete, our
final example illustrates a session-counting service. The server code
keeps a current counter in memory and returns this value to the
client. When Scope
is set to
Session
, the rpcrouter
will
instantiate a new service object for each client. The server is
therefore able to maintain individual session counts for each client.
When Scope
is set to
Application
, the rpcrouter
will
instantiate only one service object; the server therefore counts the
total number of requests from all clients.
Get Web Services Essentials now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.