Create and Deploy Web Service and Web Service Client in Eclipse
In our previous tutorial, we got introduced to Web Services and the Concept associated with web service technology. In this article we shall learn to Create and Deploy Web Service and Web Service Client in Eclipse.
There are two ways to develop a web service namely top-down approach and bottom-up approach. To know about these approaches and in general about web service refer my Concept associated with web service article. In this article we will be using bottom-up development approach.
Environment Used
JDK 7 (Java SE 7)
Eclipse JUNO IDE
Apache Tomcat 7.x
Just for your information, Eclipse by default uses Apache Axis to implement the web service and it provides option to use our choice of web service engine. I decided to go with the default bundled Apache Axis.
Initially Install Eclipse IDE and configure apache tomcat in it, and Create a dynamic Web Project with the following configuration
Now create a simple calculator java program as with the code below
File: Calculator.java
package com.webServices; public class Calculator { public int add(int a, int b) { return (a + b); } public int subtract(int a, int b) { return (a - b); } public int multiply(int a, int b) { return (a * b); } public int divide(int a, int b) { return (a / b); } }
Initial Project Structure
The initial project structure of application should be as shown below
Now Right Click on file Calculator.java -> Web Services -> Create Web Service and Select options as mentioned in below diagram and Click finish.
Here we are instructing Eclipse to generate a web service and its client. These steps will create a new dynamic web java project WebServicesClient
.
Final project structure:
Both WebServices and WebServicesClient projects will be automatically deployed to server. Also, Eclipse automatically opens Web Service Test Client Window with URL: http://localhost:8089/WebServicesClient/sampleCalculatorProxy/TestClient.jsp?endpoint=http://localhost:8224/WebServices/services/Calculator
Now click on add(int,int), subtract(int,int), divide(int,int) ,multiply(int,int)
on the Web Service Test Client Window and provide an input to check updated result.
That’s all on how to Create and Deploy Web Service and Web Service Client in Eclipse.
Happy learning :)
It is such an superb tutorial for a beginner just like me. I have successfully created and consumed a web service. Thanks a lot!
Glad it worked for your. Thanks for sharing moment.