Create Web Service Eclipse

This demo will demonstrate the use of newly introduced Axis2 Web Service tool to create simple web service.
Below are needed:

  • Eclipse 3.6 or above (Download eclipse from http://www.eclipse.org/downloads/ site). I have user latest version of Eclipse Kepler Service Release 1
  • JDK 1.6 or above (Download from here: http://www.oracle.com/technetwork/java/javase/downloads/index.html)
  • Tomcat 6 or above (Please follow link to install and configure tomcat in eclipse:Configure and Run Tomcat server in eclipse

Below are the steps:

  • Create dynamic web project name ConverterWebService (If you are not sure how to create dynamic project in eclipse please use this link: Create Dynamic Web Project Eclipse)

Note: During dynamic project creation choose Dynamic web module version 2.5

Create Web Service Eclipse

  • Once project created then create service class called Converter.java inside package com.javahorn.converter and copy paste below content in it
package com.javahorn.converter;

public class Converter {
	public float celsiusToFarenheit(float celsius) {
		return (celsius * 9 / 5) + 32;
	}

	public float farenheitToCelsius(float farenheit) {
		return (farenheit - 32) * 5 / 9;
	}
}

Create Web Service Eclipse

  • Right click Java Resouces –>New –>Other –> Web Serives –> Web Service –>Click Next

Create Web Service Eclipse

Create Web Service Eclipse

You will see below screen.

  • Service Implementation: Select Converter.java class you have created before
  • Move the slider all the way up to Test Service
  • Web Service runtime: Apache Axis2
  • Client Type: We are not generating client for this demo move the slider all the way to bottom no client
  • Click Next

Create Web Service Eclipse

Web Service Java Bean Identity:

  • WSDL file: This name will come by default as web service java class name
  • Methods: Whatever method we have created in Converter.java class
  • Style and Use: Select document/literal (Wrapped)
  • Click Next

Create Web Service Eclipse

  • Server Setup: Tomcat is configured with eclipse that will be selected –> Click Start server (Server will be started) then click Next (If you are not sure how to configure tomcat in eclipse please use this link: Configure and Run Tomcat server in eclipse)

Create Web Service Eclipse

  • Click Next and Let’s Test facility default selected

Create Web Service Eclipse

  • Click Finish

Create Web Service Eclipse

  • When you click Finish –> Eclipse will create web service and it will open Web Service Explorer for test as below where you could see two method which you created in Converter.java class. Select celsiusToFarenheit method to test you will see result as below.That’s it.

Create Web Service Eclipse

  • That’s it.

download2 Download project: ConverterWebService

Leave a Reply

Your email address will not be published. Required fields are marked *