# JAX-WS (SOAP) Client in Spring

In 
Published 2022-12-03

This tutorial shows you how to create a JAX-WS (SOAP) web service client.

SOAP is an XML specification for sending messages over a network. SOAP messages are independent of any operating system and can use a variety of communication protocols including HTTP and SMTP.

JAX-WS is a framework that simplifies using SOAP. It is part of standard Java.

In order to create a SOAP web service in Spring Consumer (Client), you have to create a simple Spring application and configure it to use Maven.

Here is the pom.xml file dependencies:

Now we have to create the following classes:

package com.example.ws;
 
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
 
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
 
@WebService(serviceName="MyServiceA_WSService", targetNamespace="http://ws.example.com/")
@Component
public interface IMyServiceA_WsCall {
 
    @WebMethod
    public String addNumbers(
            @WebParam(name = "value1") int value1,
            @WebParam(name = "value2") int value2); 
}
package com.example.ws;
 
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
 
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
 
@WebService(serviceName="MyServiceA_WSService", targetNamespace="http://ws.example.com/")
@Component
public interface IMyServiceA_WsCall {
 
    @WebMethod
    public String addNumbers(
            @WebParam(name = "value1") int value1,
            @WebParam(name = "value2") int value2); 
}
package com.example.main;
 
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
 
import com.example.config.SpringContextConfig;
import com.example.ws.IMyServiceA_WsCall;
 
//Main JAX-WS Client
public class Main {
 
    public static void main (String [] args) {
         
          System.out.println("Start ...");
           
          AnnotationConfigApplicationContext context 
            = new AnnotationConfigApplicationContext(SpringContextConfig.class);
           
          IMyServiceA_WsCall myServiceA_WsCall = 
                  context.getBean(IMyServiceA_WsCall.class);
           
          System.out.println(myServiceA_WsCall.addNumbers(10, 11));
         
          context.close();
    }
}

When I run the application I receive:

As you can see the context is not closed and the application is still running.