Overview

In the previous article we have gone through an overview of SOAP web service and advantage and disadvantage of it. In today’s article, we will create SOAP web service using JAX-WS libraries.

JAX-WS is a Web Services framework that provides tools and infrastructure to develop Web Services solutions for the end users and middleware developers.

There are two communication style models that are used to translate a WSDL binding to a SOAP message body. They are Document & RPC. We will discuss it in detail in coming articles. Here we will create a Web Service with RPC style.

Let’s understand steps with Stock Application, We have stock service which will give us a stock price based on the registered stock name.

Steps to Create SOAP Web Service

Let’s first create Dynamic Web Project with name ‘StockWebservice’ in eclipse.

Directory structure of Project
Directory Structure
Directory Structure
1. Create a Web Service Endpoint Interface

@SOAPBinding is used to define style of Web Service.

2. Create a Web Service Endpoint Implementation
3. Create a web service deployment descriptor

When user access /stockendpoint URL path, it will fire the declared web service, which is StockEndPointImpl.java.

4. Create a standard web.xml deployment descriptor

Within web deployment descriptor we defines WSServletContextListener as listener class, WSServlet as your StockEndPoint servlet.

5. JAX-WS Dependencies

By default Tomcat does not come with JAX-WS dependent libraries, So, We have to include it manually.

Dependencies can be download from here

Add listed jars in tomcat lib folder or add it in web service class-path.

gmbal-api-only.jar ha-api.jar jaxb-core.jar jaxb-impl.jar jaxws-rt.jar management-api.jar policy.jar stax-ex.jar streambuffer.jar
6. Deploy Web Service.

Our service is ready, Now lets deploy it in Apache Container. Click on Project and click Run -> Run on Server.

From the service name, Our endpoint URL will be.

http://localhost:8080/StockWebservice/stockendpoint

For testing we can access endpoint URL, If we see the following a page that means service deployed successfully.

SOAP Endpoint
SOAP Endpoint

And WSDL URL

http://localhost:8080/StockWebservice/stockendpoint?wsdl

Web Service Client

Our service is ready to test, There are many ways to test SOAP Web service.

1. SoapUI

SoapUI is a third party tool to invoke endpoint. Listed are steps to invoke SOAP web service from SoapUI.

1. Create SOAP project with Project name and WSDL URL.

SoapUI Create Project
SoapUI Create Project

2. Click on request and change input param in soap envelope and run it.

Invoke SOAP Service with SoapUI
Invoke SOAP Service with SoapUI
2. Java Web Service Client

Let’s write client code in Java. Below is a client code to invoke SOAP web service from Java.

Output

1400.0

That’s all for SOAP Web Service, Hope you like it, Keep reading and sharing !! 🙂

Leave a Reply

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