Consume Soap services using spring boot

Sat, May 30, 2020

Read in 5 minutes

In this article ,we will explore how to consume SOAP service.

As REST webservice is dominating the market for the past few years and I couldn’t get opportunity to consume the SOAP service .Currently I am involving in a project where i have to consume SOAP service from the vendor product .So I brush up about the SOAP basics and I would like to share that knowledge to a fellow engineer through this blog.


Webservices :

The webservices are created to exchange the data between the two different system . Two types of webservices created are ,

SOAP Basics :



WSDL Tags :


Steps to Consume a SOAP service :

Step :1 - Create Spring boot Project and Get the WSDL

Got the WSDL and create spring boot project ,and select the dependencies - Spring web and Spring Web Services If want to know about creating boot project in detail you can follow the below URL


Step :2 Convert the WSDL to Stub


Step 3 : Understand the request ,response and their types

SOAP5 Update the SOAP URL and click ok for the next dialogue boxes .

SOAP6 Now you can see all the operations list on the screen and click any one of the request . And update <blz:blz>46062817</blz:blz>.Then click the green triangle to run .


And the response is ,


Step:4 Form the request object by mapping data and call the soap uri

package com.theprogrammerguide.consumesoap;
import com.theprogrammerguide.consumesoap.stub.GetBankResponseType;
import javax.xml.bind.JAXBElement;
public class SoapClient extends WebServiceGatewaySupport {
public GetBankResponseType getBank(String url, Object request){
JAXBElement res = (JAXBElement) getWebServiceTemplate().marshalSendAndReceive(url, request);
return (GetBankResponseType) res.getValue();

public class BeanConfig {
public Jaxb2Marshaller marshaller()  {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
return marshaller;
public SoapClient soapConnector(Jaxb2Marshaller marshaller) {
SoapClient client = new SoapClient();
return client;

Here in the BeanConfig , we create Jaxb2Marshaller object and set the context path .This Jaxb2Marshaller object is used to create java object from the response XML.

Test the Spring Boot code and get the Response :

To Test the spring boot create a controller and call the SOAP client and pass the request data. Here you have to get the code as a query param .So ,using this controller you can map a endpoint and test the API.

package com.theprogrammerguide.consumesoap.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.theprogrammerguide.consumesoap.SoapClient;
import com.theprogrammerguide.consumesoap.stub.DetailsType;
import com.theprogrammerguide.consumesoap.stub.GetBankResponseType;
import com.theprogrammerguide.consumesoap.stub.GetBankType;
import com.theprogrammerguide.consumesoap.stub.ObjectFactory;

public class BlzController {

private SoapClient soapClient;

public DetailsType sum(@RequestParam String code) {
ObjectFactory objectFactory = new ObjectFactory();
GetBankType type = new GetBankType();
// BlzServiceAdapter blzServiceAdapter=new BlzServiceAdapter();

GetBankResponseType response = soapClient.getBank("",
return response.getDetails();

Test with the URL :http://localhost:8080/?code=46062817