In this tutorial you will learn about java soap web services.
In my previous tutorial I have given the basic overview of web services. I would recommend you to read it first.
SOAP
SOAP is the short form of Simple Object Access Protocol. It is a platform independent and XML based protocol. The web services developed using this protocol are called soap web services.
WSDL
WSDL is the short form of Web Service Description Language. It is a XML based document that contains all technical details of web service. Client uses this file to get information about a web service.
JAX-WS
It is an API provided by Java that is used for developing soap web services.
Advantages
It defines its own security and it is highly secure. Mainly used where security is major concern and resources are not limited.
Disadvantages
Let’s make a very basic soap web service in java using eclipse ide that will find square of a number.
Make sure eclipse contains following things.
Apache Tomcat: It is the server for running our web service.
Apache Axis: It is the tool that is used to create web service using java class.
1. Open eclipse ide and create a new dynamic web project by going to File > New > Dynamic Web Project.
2. Make a package under src folder of your project. Here I am creating package with name com.
3. Now create a class under this package and add following code inside it.
DemoService.java
package com; public class DemoService < public int square(int n)< return n*n; >>
4. Right click on the java class and select Web Services > Create Web Service.
5. You will get a window as shown below. Pull two blue bars at top and select all three options at bottom.
Services Tutorial 3" width="705" height="728" />
6. Finally click on Finish button to create the web service.
7. You will see a screen as shown below. It is a client test jsp page. We can use it to test the web service. At left you can see the square() method that we have used in our web service class. Just click on it. Now enter a number in the text box and click on Invoke button to invoke the method. At bottom you can see the square of the number you entered.
Here I have used just one method. You can create any number of methods. Just make sure the method is public.
Go to wsdl folder inside WebContent in your project. There you will find a wsdl file. It contains each and every information about our web service like web service location, method names, method arguments, their type, etc.
Open the wsdl file and scroll to bottom. There you will find a tag. It contains the location of the web service. Just copy the location and add ?wsdl at the end of url.
The url may look like this http://localhost/SOAPWebService/services/DemoService?wsdl
Open this url in browser. It is the url by which you can access the wsdl file of your web service.
DemoService.wsdl
Comment below if you are facing any problem related to above java soap web services tutorial.