||| Being somewhat new to SOAP (and having pored over severalHere is what I do (I use the latest beta 1 release):
||| books/resources), I'm finding a lack of explanation out there on how to
||| do "Stateful" SOAP servers (in the same way that it's trivial to do
||| Stateful JSP's/Servlets).
|||
||| Basicly I want to provide a SOAP API with methods like:
|||
||| logon()
||| putItem()
||| getItem()
||| removeItem()
|||
||| And I want for the SOAP client to be required to call logon() before
||| calling any other method on my server... Any deviation throwing a
||| "fault" or something.I'm facing the same problem right now with a client. What we are planning
on doing is to pass to the client code a "transaction token" that we create
in the login process. The client code will then pass this token as the
first argument of each successive service invocation. We didn't see any
other way to do it. I think the SOAP that comes with WLS6.1 has some
statefull qualities, but it doesn't work with all client implementations.
(I could be wrong about that; we've been doing rapid research on this and
this is what we found...)Does anyone have a better way to do it?
1. Put the following line into the service's .wsdd file:
<parameter name="scope" value="session"/>
2. Generate a stub for the deployed service with the WSDL2Java tool
and modify one of generated files - the "...ServiceLocator.java" (in fact
I modified one of Axis's classes and put the modified class before axis.jar
in my classpath, which causes the file in question to be generated automatically
in the proper form). The "...ServiceLocator.java" file, generated by the
unmodified WSDL2ava, would contain:
public my.package.MyService getMyService(java.net.URL
portAddress) throws javax.xml.rpc.ServiceException {
try {
return new my.package.MyServiceSoapBindingStub(portAddress, this);
}
catch (org.apache.axis.AxisFault
e) {
return null; // ???
}
}
My modified WSDL2Java generates:
public my.package.MyService getMyService(java.net.URL
portAddress) throws javax.xml.rpc.ServiceException {
try {
my.package.MyServiceSoapBindingStub result = new my.package.MyServiceSoapBindingStub(portAddress,
this);
result.setMaintainSession(true);
return result;
}
catch (org.apache.axis.AxisFault
e) {
return null; // ???
}
}
The first call to a method in the MyService service creates an HTTP session and a new service object, attached to it. The session's ID is passed back and forth between the client and the server in a cookie (whithout any additional intervention).
Jarek