DEV Community


Posted on

SOAP web service with JAX-WS

In tutorial you will learn to publish and consume SOAP based JAXWS webservice using maven

What is Soap

SOAP stands for Simple Object Access Protocol, it's a transport protocol based on XML and HTTP. It sends and receives requests and responses.

What is WSDL

WSDL or Web Services Description Language is an XML notation for describing a web service.

What is JaxWS

JaxWS stands for Java API for XML Web Services. It builds web services and clients that communicate using XML.

What is SoapUI

SoapUI is an API Testing Tool, it is used for RESTful Web Services or HTTP based services as well as SOAP Web Services.

Here is an overview of what we're going to need for this project:

  1. - A web service
  2. - A JAXWS server
  3. - SoapUI for testing purposes

To start create a Maven project :

Image description

Add a new java class, let's call it StarwarsCharacter

Now add another java class and let's call this one StarwarsService.

Within this class declare these 2 methods:

  • getStarwarsCharacter(): returns a new StarwarsCharacter
  • starwarsCharacterList(): returns a new list of StarwarsCharacters

This class is going to serve as our Webservice endpoint. In order to do that annotate it with the @Webservice annotation. And to expose its 2 methods to web service clients we're going to annotate each of them with the @WebMethod annotation.

But before we can do any of that add this dependency to you POM.XL file:

<!-- -->

Enter fullscreen mode Exit fullscreen mode

Our class should look like this:

Now let's deploy our webservice

Add a Server class that will publish the webservice endpoint to accept incoming requests using the method publish()

This method takes as arguments: the http server address and an instance of the webservice.

It return an http server that runs on the port passed in the address parameter and it is used to access the webservice passed as the implementor parameter.

To access the wsdl :


Testing the webservice

Link to download SoapUI:

Add a new SOAP project as follow
Image description

To test the first method make a request and pass it your arguments

Enter fullscreen mode Exit fullscreen mode

The result:

Image description

On to the next method, this one doesn't take any arguments:

Image description

Consume this SOAP webservice

Create a new project and add the JAX dependency to the POM.XML file

Before we can proceed you need to install this plugin

Image description
Now click on the project name and go to help > Actions

Image description

Search for Generate Java code from Wsdl

Image description

Image description

It's going to generate the java classes inside your package

Image description

Add a new class that's going to use a middleware to consume your webservice

Result is as follows :

Image description

Top comments (0)