Home arrow Web Services arrow Page 4 - An Introduction to Web Services

An Introduction to Web Services

Web services are becoming more and more popular. If you would like to learn what they are and how you can develop and deploy them, keep reading.

Author Info:
By: Mamun Zaman
Rating: 4 stars4 stars4 stars4 stars4 stars / 20
May 30, 2007
  1. · An Introduction to Web Services
  2. · A closer look at SOAP, WSDL and UDDI
  3. · Web Services Development and Deployment
  4. · Getting to Work

print this article

An Introduction to Web Services - Getting to Work
(Page 4 of 4 )

You now have all necessary tool/software installed and ready. You have to create an interface for your web service. We are going to develop a web service that has just one function: the addition of two integers. The interface should look like the one below.

public interface addWS {
int add(int a, int b);

We have one function called add that takes two integers as parameters and returns an integer. Now we need to compile this into .class.

Create WSDL from the Java Interface. AXIS comes into action for the first time here. We will use one tool that comes with AXIS -- Java2WSDL, for creating WSDL files from Java interfaces (to do this you don't need any knowledge of WSDL!). Use the following command to create the WSDL.

java org.apache.axis.wsdl.Java2WSDL -o add.wsdl -l"http://localhost:8888/axis/service/add" addWS

Here,org.apache.axis.wsdl.Java2WSDL is the main class, -o defines the output WSDL file name (add.wsdl), -l is used for the URL you would use to locate your service, and finally the interface class (without the .class extension). I assume you are in the folder where the interface class resides.

Create Java Classes from WSDL. At first it may seem a bit confusing as we just created a WSDL from Java. For sending and receiving SOAP messages you need to use RPC, XML, HttpRequest and HttpResponse in a very complex way. We want AXIS to do this for us. If we use the WSDL2Java tool then AXIS will create all necessary classes for us for XML-RPC and others.

java org.apache.axis.wsdl.WSDL2Java -o . -d Session -s -p addService add.wsdl

Here, -o as usual is the location of the output directory (.), -d defines it as session meaning your Java classes will be created for each session (other values for -d are Application and Request), and -p defines the output package name.

Modify the Java Classes. After creating all the classes from WSDL, we need to implement the interface we created earlier. Actually WSDL2Java creates a Java class called XXXSoapBindingImpl.java (XXX represents the service name) implementing the interface already described. We just need to put the logic into this class.

Create Jar. Create a .jar archive file including all these classes and copy it into the lib folder of axis. The location usually is $TOMCAT_HOME/webapps/axis/WEB-INF/lib. Use the jar command - jar cvf filename.jar folder_to_jar.

Deploy the Web Service using WSDD (Web Services Deployment Descriptor). When we used WSDL2Java, with all the Java classes two .wsdd files are also created. One is deploy.wsdd and the other is undeploy.wsdd. These descriptors are used for deploying and undeploying web services accordingly. Use the command shown below to deploy the service. You may need to restart Tomcat for completing the deployment.

For deploying your service, go to the folder where your deploy.wsdd file is. Then issue the following command.

java org.apache.axis.client.AdminClient -l http://localhost:8888/axis/services/AdminService deploy.wsdd

Here, http://localhost:8888/axis/services/AdminService link locates the AdminService of AXIS as described earlier. To find the link click the AdminService link from AXIS list. You will get a page similar like the below. The link for AdminService is without the ?wsdl part of the address shown.

After deployment your service will be displayed in AXIS list link.

We have completed the development and deployment of web services using Apache AXIS. This way of developing web services is very simple, but if you want an even simpler way than this you can use the Netbeans IDE. The Netbeans IDE lets you develop web services by merely dragging and dropping.

We talked mainly about creating and deploying web services in this article. I tried to focus on all the areas of developing web services using Java technology with AXIS. In the future I will describe how to create a web service client in PHP, .NET and Java, if you want. To learn more about Apache AXIS and the tools mentioned here please visit the Apache web site for AXIS at http://ws.apache.org/.

DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus

- Dealing with Loose Coupling in a Service-Ori...
- Loose Coupling in a Service-Oriented Archite...
- Safety, Idempotence, and the Resource-Orient...
- The Resource-Oriented Architecture in Action
- Features of the Resource-Oriented Architectu...
- The Resource-Oriented Architecture
- Getting Started with Flex
- Automated Billing and Faxing for the Web
- An Introduction to Web Services
- The Foundations of Web Services: From Novice...
- Web Services Reengineering: Finishing Touches
- Fault Handling with Web Services
- Flow and Web Services
- Process Lifecycles and Web Services
- Business Processes and Web Services

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials