In the bottom up approach, we will write the java class and generates the WSDL file and other dependent components. The same will be deployed into the web containers.
In Top down approach, Architects will write the WSDL file based on the requirements. Developer need to make the corresponding service implementation using the WSDL provided. This post will explain how to create a service using the WSDL file.
Step 1: Create a dynamic or java project as mentioned here
Here, I have created a sample web dynamic project with the name SampleWS as given below.
Step 2: generate the service using top down approach
Right click on the SamplWS project name -> New -> Other
Select the Web Service from the wizard as below and click on Finish button.
Select the Web service type as ‘Top down Java bean Web service’ and provide the WSDL url in the Service definition drop down and click on Finish button.
Sample WSDL URL is: http://localhost:8080/SampleWebService/wsdl/Calculator.wsdl
Your Web service is ready with the Java bean methods as below and the Final folder structure looks like below:
Write the business logic into the Service class as given below:
Generated class:
/**
* CalculatorSoapBindingImpl.java
*
* This file was auto-generated from WSDL
* by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter.
*/package in.malliktalksjava;
public class CalculatorSoapBindingImpl implements in.malliktalksjava.Calculator{
public int addition(int var1, int var2) throws java.rmi.RemoteException {
return -3;
}public int multiplication(int var1, int var2) throws java.rmi.RemoteException {
return -3;
}public int division(int var1, int var2) throws java.rmi.RemoteException {
return -3;
}}
Implemented class:
/**
* CalculatorSoapBindingImpl.java
*
* This file was auto-generated from WSDL
* by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter.
*/package in.malliktalksjava;
public class CalculatorSoapBindingImpl implements in.malliktalksjava.Calculator{
public int addition(int var1, int var2) throws java.rmi.RemoteException {
return var1+var2;
}public int multiplication(int var1, int var2) throws java.rmi.RemoteException {
return var1*var2;
}public int division(int var1, int var2) throws java.rmi.RemoteException {
return var1/var2;
}}
Deploy the application into server and use the below url as a WSDL for this to have the client.
http://localhost:8080/SampleWebService/wsdl/Calculator.wsdl
Other Useful Links:
Click here to know more about webservices
Click here to know more about RESTfull web services.
Click here for Web services Question and Answers.
Click here to know how to write web service client suing java.
Filed under: Web Services Tagged: client stubs, creating a web service using java, Generating webservice client stubs, how to generated web service client stubs in STS, Java, java project, Java Web services, javatutorials, Service-oriented architecture, SOAP, software, Web service, web service client, Web Service Description Language, webservices, writing webservice client using S, WSDL
