Archive for November, 2007
Calling a stateful Web Service with JBossWS
Although Web Services are usually described as stateless and involving distributed applications exchanging one-off messages here and there, stateful web services are not that uncommon. I recently spent some time trying to invoke a stateful .Net service from JBoss (using JBossWS) and I thought I’d post the code for that here.
The .Net service required login before further methods on it are invoked. This scenario is probably quite common out there as more and more 3rd party server-side components that require authentication get exposed as web services. A web service can be made stateful by using the SOAP header to stuff state information or by setting cookies in the HTTP session. The web service I was invoking used cookies, so I will talk about that here.
The following enables cookie support on the the web service client side:
Service service = Service.create(wsdlURL, serviceQName);
ServiceInterface proxy = (ServiceInterface)service.getPort(ServiceInterface.class);
((BindingProvider)proxy).getRequestContext().put( BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
However, doing this in itself IS NOT ENOUGH! Because of a bug in JBossWS, only versions of JBossWS 2.0.1 and newer have the above working correctly. JBossWS 2.0.1 was released fairly recently - the release date is listed as 17 Aug 2007. JBossWS comes with JBoss, however it is only since JBoss 4.2.2 GA that JBossWS 2.0.1 is included (older versions of JBoss have JBossWS 1.x instead).
Basically to make the above work you will need the latest versions of JBossWS or JBoss (as of the time of this writing) because versions from as recently as a few months ago won’t work.
Comments(0)