Create an Axis2 Web Service in 3 Steps Using Eclipse - Bottom up approach

In just 3 easy steps, Saminda Wijeratne, Senior Software Engineer at WSO2, guides you in creating an axis2 web service using the eclipse IDE.

 

Date: Wed, 7th Oct, 2009
Level: Intermediate
Reads: 21983 Comments: 8 | Login or register to post comments
Saminda Wijeratne
Senior Software Engineer
WSO2 Inc
samindaw's picture

Introduction

Within few minutes, you will learn how to create an axis2 web service using the eclipse IDE in just 3 easy steps.

 

The 3 steps are:

  1. Creating an Eclipse Project with WSO2 WSAS Facets added
  2. Add a Java Class to the project
  3. Make that Java class exposed as a web service

Prerequisites

eclipse

3.4 or higher
Java 1.5 or higher
WSO2 WSAS 3.1.x
eclipse features

Web Service Authoring & Testing Tools - v1.1.0

WSO2 WSAS Server v3.1 - v1.0.0

 

 

 

 

 

 


Note: Visit the resources section of this tutorial to find out from where to download the prerequisites or click the above links.

Step 1 - Create a Dynamic Web Project with WSAS Facets

eclipse IDE
 

Go to File->New->Other... (Or "Ctrl + N")
Select Dynamic Web Project.

 


Type in a "Project name"


In "Target runtime" if "WSO2 WSAS 3.1" not available, click "New"
Select "WSO2 WSAS 3.1" from the list and click next.


Specify WSAS distribution path.


Click "Finish"


In "Configuration" click "Modify"

Tick/Check "WSAS Web Services" and click OK

Click "Finish"

 

Step 2 - Create the Java Class


Go to File->New->Other... (Or "Ctrl + N")


 

Select "Class" and click "Next"
Put the package name and name of the class


Click "Finish"


Lets have the following code.

package org.wso2.sample.webservice;

public class Area {
    
    public double getSquare(double sideLength){
        double area=sideLength*sideLength;
        return area;
    }
    
    public double getRectangle(double width, double height){
        double area=width*height;
        return area;
    }
    
    public double getTriangle(double baseLength, double height){
        double area=0.5*baseLength*height;
        return area;
    }
 
}

 

 

Step 3 - Make the class a Service

Select the Area.java class from "Project Explorer" view which is in the left handside of eclipse workspace.
Go to File->New->Other... (Or "Ctrl + N")


Select "Web Service" click "Next"


Click "Web service runtime" link and select "WSO2 Web Services Application Server" in the "Web service runtime" list box.

Click "OK".

Click "Finish"

Thats it. Your web service (provided that there aren't any syntax or coding errors) will be published in WSAS server.


 

When the WSAS server starts it will open the WSAS home page of WSAS server in an external browser. You can click the "List" link under services to see which services are available in the server.

 

Click on the "Try this service" link infront of the "Area" service to invoke your web service.

 

Resources

  1. Java class which we would create the web service from can be downloaded from here.
  2. To download WSO2 WSAS please visit https://wso2.org/projects/wsas/java
  3. To download WSO2 WSAS Tools please visit https://wso2.org/projects/tools/ or use the update site URL http://tools.wso2.org/eclipse

Summary

So creating a web service is easy. All you have to do is to point to the class which you want to make it a web service.

Click here to find out how to create a web service client for this service 

Author

Saminda Wijeratne, Senior Software Engineer, WSO2, samindaw@wso2.com

srinidhibavanaka.gmail.com's picture

Issue with the final step of the deployment

I have Wso2 server on my machine and when i tried to follow the above steps on Eclipse EE version it gave me java.lang.NoClassDefFoundError: and Caused by: java.lang.ClassNotFoundException: and at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source) Exception in thread "main" Do i need to set separate paths for creation of a web service on Eclipse? Any Comments or help is appreciated. Thanks.
samindaw's picture

I think this thread is

I think this thread is http://wso2.org/forum/thread/8695 is related to this issue.
xieshiqi1986.gmail.com's picture

nike dunks high

http://www.nikedunk2012.org/
lupuerotic.gmail.com's picture

Eclipse

I found many tutorials on the internet about using Eclipse , and it is no wonder , it is a great piece of software for web design , with easy to use interface and many tools for customizations, I read somewhere that even big companies like encore marketing use it for their clients.
cedric.bonhomme.tudor.lu's picture

Problem at the end of the step 3.

Hello, At the end of the step 3, I have this problem: "Unable to add the follwing facets to project AreaServiceProject: WSAS Web Services Core, WSAS Web Services Extensions." With the details: """ Unable to add the follwing facets to project AreaServiceProject: WSAS Web Services Core, WSAS Web Services Extensions. org.eclipse.wst.common.project.facet.core.FacetedProjectFrameworkException: Failed while installing WSAS Web Services Core 1.1. at org.eclipse.wst.common.project.facet.core.internal.FacetedProject.callDelegate(FacetedProject.java:1497) at org.eclipse.wst.common.project.facet.core.internal.FacetedProject.modifyInternal(FacetedProject.java:438) at org.eclipse.wst.common.project.facet.core.internal.FacetedProject.mergeChangesInternal(FacetedProject.java:1171) at org.eclipse.wst.common.project.facet.core.internal.FacetedProject.access$2(FacetedProject.java:1107) at org.eclipse.wst.common.project.facet.core.internal.FacetedProject$1.run(FacetedProject.java:321) at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1800) at org.eclipse.wst.common.project.facet.core.internal.FacetedProject.modify(FacetedProject.java:336) at org.eclipse.jst.ws.internal.consumption.ui.common.FacetOperationDelegate$1.run(FacetOperationDelegate.java:62) at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121) Caused by: org.eclipse.core.runtime.CoreException: lib (No such file or directory) at org.wso2.wsf.ide.facet.deligate.WSASCoreFacetInstallDelegate.execute(WSASCoreFacetInstallDelegate.java:87) at org.eclipse.wst.common.project.facet.core.internal.FacetedProject.callDelegate(FacetedProject.java:1467) ... 8 more Caused by: java.io.FileNotFoundException: lib (No such file or directory) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.(FileInputStream.java:106) at org.wso2.wsf.ide.core.utils.FileUtils.copy(FileUtils.java:159) at org.wso2.wsf.ide.facet.utils.WSASWebappUtils.copyWSASWar(WSASWebappUtils.java:109) at org.wso2.wsf.ide.facet.commands.WSASWebservicesServerCommand.exexuteOverride(WSASWebservicesServerCommand.java:54) at org.wso2.wsf.ide.facet.deligate.WSASCoreFacetInstallDelegate.execute(WSASCoreFacetInstallDelegate.java:77) ... 9 more """ I think that it lacks a ./lib folder somewhere. Or I have a problem in a class path, maybe... My WSO2 Runtime is here: /opt/wso2wsas-3.2.0 My AXIS2 runtime is here: /opt/axis2-1.5.1 And I have the messge "Axis2 runtime loaded successfully". And just before, when I created the Dynamic Web Project "AreaServiceProject" I had a warning about the ./lib/ folder... Can anyone help me? Thanks!
cedric.bonhomme.tudor.lu's picture

Problem at the end of the step 3.

And for the first problem (which is for sure linked) I have this message: """ Failed while installing WSAS Web Service Core 1.1. Reason: lib (No such file or directory) """ This happens just when I click on Finish at the end of the step 1...
siva.tammana.zoraly.com's picture

Hi, Webservices authoring and

Hi, Webservices authoring and testing tools are not present in this location can you please specify the location http://wso2.org/download/tools/wsas/wsas-authoring
tylerbrad99.yahoo.com's picture

jacket from fight club

Nice post like it so much. http://www.celebswear.com/products/Brad-Pitt-Fight-Club-Jacket-.html