wood burning stoves 2.0*
The moose likes Web Services and the fly likes Sessions in Axis Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Sessions in Axis" Watch "Sessions in Axis" New topic
Author

Sessions in Axis

Cory Wilkerson
Ranch Hand

Joined: Aug 14, 2001
Posts: 84
I have both java and .net clients using a web service I've built -- both clients are generating source code from the service's wsdl description. It seems to me as if subsequent client requests aren't maintaining state and I'm wondering if there's something I can congfiure server side to force state maintenance.
Anyone, anyone?
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Stateful web services are a bad, bad, bad idea. Maintaining cookies or session id's is totally outside of the SOAP specification -- it's not guaranteed, so you can't be assured it will happen.
Web services should always be stateless. If you need to store client-specific state, store it in a database, and pass the key with each Web Services call as a parameter.
Kyle


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Hi Cory,
I too had a java and .NET clients, recently my .NET clients(C#)is generating some errors which i'm trying to solve.
May I know what software you are using for creating .NET clients,any online resources,books you used.
I'm using http://www.asp.net toolkit for generating my .NET client.
Thank you.
Regards
Balaji


Spritle Software Blogs
Brian Abbott
Greenhorn

Joined: Sep 10, 2004
Posts: 1
I totally disagree with Kyle that the idea of passing session information in webservices somehow violates design ideas or negates the benefits of Web Services. Web Services is ultimately a mechanism for software component interaction. Theres no reason against or shortfall that you will encounter with using session information in Web Services.

The best way to pass session information is to include a session id in the SOAP Header. In AXIS, heres how you can do this:

class SOAPInvocationHandler implements InvocationHandler
{
String endpoint;
Service service;
Call call;

public SOAPInvocationHandler(String _endpoint)
{
endpoint = _endpoint;
service = new Service();
try
{
call = (Call)service.createCall();

// SET YOUR HEADER HERE.
call.addHeader(instanceOfSOAPHeaderElement);
}
catch(ServiceException se)
{
se.printStackTrace();
}
}

// your invoke method
public Object invoke(Object proxy, Method method, Object[] args)
{
}
}

In fact, the SOAP Standard supports this. For more information, the W3C recommendation can be accessed here: http://www.w3.org/TR/soap12-part1/ Section 5.2.1 covers custom header elements. Basically what they are saying is that while not every SOAP Processing engine must understand your unique element, no processor should crash on it.

This code also demonstrates creating an object proxy which can be useful on client-side programming.

Cheers,

Brian Abbott
 
wood burning stoves
 
subject: Sessions in Axis
 
Similar Threads
Cade Part 2 Example - How is Session Maintained?
question about JMX
Pool for Stateless Session Beans ??
Locking Questions
recommended IDE for Struts 2?