Wednesday, April 06, 2005

Web Services...

Some notes on consuming a web service.

I have just been working with a new web service which has been provided to us. First of all get hold of the WSDL. Then use Apache Axis's WSDL2Java program to create Java classes which you can use to interact with the service. Originally I used Axis 1.2 RC3 to create the classes but ran into a problem with the created classes serializing attributes of basic classes (specifically, in java.math.BigInteger). See this page for an explanation - http://www.mail-archive.com/axis-dev@ws.apache.org/msg05287.html - I ended up going back to Axis 1.1 which appears to work OK in this regard.

The WSDL2Java creates a bunch of Java source files, which I put into JBuilder and created the class files from that. Then I put those classes into a webapp and deployed it on Tomcat. Tried to get it deployed on Weblogic but the usual configuration nightmare defeated me.

Having created the classes, you then have to figure out how to use them!
In the case of my web service, I created the various header objects it needed, and the object which contains the search parameters (this is highly service-dependent I assume), then instantiated the Locator class for the service, and from that created the SOAP Stub class. These classes are all created from the WSDL.

Then it's a case of calling the appropriate method on the stub in order to invoke the particular operation you want. From this you get back an response object which you can do what you like with.

This was just for testing purposes: all the calls went straight into a JSP which takes some parameters from a HTTP request and calls the service on that basis. I guess the proper production version would use beans...

Sorry if this is very generalized, but I don't want to put anything specific about the service in this blog coz it's not supposed to be for public consumption. I really just wanted to scribble something down so that I don't have to start from scratch next time!

Labels: