Filed in archive
Web Services
by jason on October 22, 2005
What follows is a fairly high level explanation of how to create a web service with Apache axis. We'll start with the idea that a web service client wants to retrieve a widget. The client will provide two parameters which will be the type of widget and the serial number of the widget. What will be returned to the client is a JavaBean that contains the contents of the widget requested. What I love about this example is the complete lack of XML parsing on the client side of this example. Axis takes care of the serialization of the bean on the server side and then the deserialization on the receiving side by adding the code the the bean for you upon deployment.
First, download the latest Axis distribution from the Apache site. Deploy the sample "axis" web application, that is provided with the Axis distribution, to a servlet engine like Tomcat. Get the distribution to display the happyaxis.jsp without any errors by following the Axis documentation. After that is up and running you are ready to start playing around with your own web services.

Above is a very simple Widget Lookup service that I want to expose to the world through a web service. It contains a helloWorld method that I can use to test with later if I run into connectivity problems. There is also a simple method that takes two parameters and returns a JavaBean. Add your own simple service class to the axis sample application with supporting business logic and JavaBean that will be populated and returned.
It is at this point, and after a few hours of pain, that I break from the Apache documentation. They suggest that you use "java org.apache.axis.client.AdminClient" to deploy the service but I simply change the server-config.wsdd and redeploy the application as a *.war file. Below is an example of the entry I put in the WSDD file within the web application. Recreate the war file and redeploy to Tomcat or whatever servlet engine is being used.

The entry above exposes the two WidgetLookup methods (helloWorld(),widgetRecordLookup(type, serialNumber)) and the WSDL for the newly available web service can be see at http://localhost:8080/[you context path]/services/WidgetLookup?wsdl (the exact URL will depend on your environment). This WSDL is now important because it will allow you to create your own test client using the Axis utility WSDL2Java (I talked about this in an earlier entry here).
After running WSDL2Java against the exposed WSDL of your web service you can now test your work. Below is a shot of the client I created to test my web service. Notice the fact that there is no need to parse any XML. The client simply gets back a JavaBean that contains the Widget.

I realize that some of this is a bit over simplified but I'm trying to keep it short and sweet. If anyone has any questions leave me a comment or email me at java@creative-weblogging.com.
First, download the latest Axis distribution from the Apache site. Deploy the sample "axis" web application, that is provided with the Axis distribution, to a servlet engine like Tomcat. Get the distribution to display the happyaxis.jsp without any errors by following the Axis documentation. After that is up and running you are ready to start playing around with your own web services.

It is at this point, and after a few hours of pain, that I break from the Apache documentation. They suggest that you use "java org.apache.axis.client.AdminClient" to deploy the service but I simply change the server-config.wsdd and redeploy the application as a *.war file. Below is an example of the entry I put in the WSDD file within the web application. Recreate the war file and redeploy to Tomcat or whatever servlet engine is being used.

After running WSDL2Java against the exposed WSDL of your web service you can now test your work. Below is a shot of the client I created to test my web service. Notice the fact that there is no need to parse any XML. The client simply gets back a JavaBean that contains the Widget.

Permalink: Creating a Web Service with Apache Axis
Trackback: http://publish.creative-weblogging.com/publish/mt-tb.pl/10496
Mr Wong
Vote for Creating a Web Service with Apache Axis:
|
Rating: 5.83 out of 6 vote(s) cast.
|
Response from:
Vivid DVD
(03/14/07 3:24pm)
If you're developing a Web service client, you'll need to know how to communicate with a remote Web service. This is basics.
Subscribe
Use the search to look for other interesting posts
| RSS | See all blog subscribe options |
|
What is RSS? | |
| Yahoo! |
|
| Addthis |
|
| Bloglines |
|
| Newsletter | |
| Follow us on Twitter! |










