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
- 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; } }
- Right click Java Resouces –>New –>Other –> Web Serives –> Web Service –>Click Next
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
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
- 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)
- Click Next and Let’s Test facility default selected
- Click Finish
- 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.
- That’s it.
Download project: ConverterWebService