Java SOAP Web Services Tutorial

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.

Read: Java Web Services Tutorial

Java SOAP Web Services

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 and Disadvantages of 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

  • Slower as compared to REST web services.
  • Requires high bandwidth and resources.
  • It supports only XML data format.
  • Difficult to implement.

 

Create SOAP Web Service Using Eclipse

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.

Java SOAP Web Services Tutorial 1

 

DemoService.java

 

4. Right click on the java class and select Web Services > Create Web Service.

Java SOAP Web Services Tutorial 2

 

5. You will get a window as shown below. Pull two blue bars at top and select all three options at bottom.

Java SOAP Web Services Tutorial 3

 

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.

Java SOAP Web Services Tutorial 4

 

Here I have used just one method. You can create any number of methods. Just make sure the method is public.

 

WSDL File

Java SOAP Web Services Tutorial 5

 

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 <wsdlsoap:address> 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.

2 thoughts on “Java SOAP Web Services Tutorial”

Leave a Comment

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