Login

Create a webservice using apache axis2

Rodrigo

By Rodrigo

Created 2014-06-23 01:59:18 Modified 2014-06-23 06:05:28

Axis 2 is a web service framework for developing webservices in java.

Axis2 provides the capability to add Web services interfaces to Web applications. It can also function as a standalone server application

In this tutorial we are going to use this framework to develop a webservice with 4 basic arithmetic methods.

this tutorial was written using the following gear:

  • Hardware: laptop Thinkpad E430 Intel I5, 4gb Ram, 500gb HDD
  • OS:           x86_64 GNU/Linux Ubuntu 14.10
  • Kernel:      3.13.0-29-generic
  • IDE:          Eclipse Java EE IDE for Web Developers
  • JDK:          1.8.0_05
  • Axis:         Apache Axis2-1.6.2

 

1.- Installation:

first we need to download the framework, go to http://axis.apache.org/axis2/java/core/download.cgi and download the latest zip

 

then we have to install it on eclipse, unzip the zip and go to eclipse → window → preferences → web services → axis2 preferences and give the path where you extracted the framework

2.- Creating the project:

now we are going to create a dynamic web project, click File → new → other → dynamic web project 

click next, in the name project type wsAxis2

now go to Configuration → Modify, and check the axis2 modules

click ok, and finish in the previous window and the project will be created

3.- Creating the webservice:

now in the project do right click → new → class and create a new class “Arithmetic” inside the package com.rrivero.example

now add theese 4 methods to the new class

package com.rrivero.example;

public class Arithmetic {
	
	public double addition(double num1, double num2){
		return num1+num2;
	}
	
	public double subtraction(double num1, double num2){
		return num1-num2;
	}
	
	public double multiplication(double num1, double num2){
		return num1*num2;
	}
	
	public double division(double num1, double num2){
		return num1/num2;
	}

}

now do right click on the class → Web services → Create Web Service  

and click Web service runtime: Apache Axis

select Apache axis2 and click ok

now in the main web service window click finish

4.- Going to wsdl:

until this point we are done, the webservice with 4 methods is published, let's see the wsdl, in your browser go to http://127.0.0.1:8090/wsAxis2/ we are going to see the main axis2 framework page

now click Services and we will see all the webservices published on this project

we have version webservice which comes with Axis2, and then we have our webservice with the 4 methods, now we are going to click our webservice “Arithmetic” and there you are, this is the wsdl of this webservice, a “webservice project” or just a project can have many webservices, and a webservice can have many methods




comments powered by Disqus