Example of SOAP RPC Web Service in Java

In this article, we will show how to create a simple RPC web service example in java using SOAP and associated with its client in a servlet container. This example is used further in Secure Web Service with Basic Authentication and Secure SOAP Web Service over SSL.

1. Create a Web Service Endpoint Interface

Let's start with creating SEI with two methods:

package example;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;

@SOAPBinding(style = SOAPBinding.Style.RPC)
public interface ExamClouds {
    String getSiteName();

    String getSiteDescription();

2. Create a Web Service Endpoint Implementation

package example;

import javax.jws.WebService;

@WebService(endpointInterface = "example.ExamClouds")
public class ExamCloudsImpl implements ExamClouds {
    public String getSiteName() {
        return "http://www.examclouds.com";

    public String getSiteDescription() {
        return "Java Tutorial";

3. Create web.xml



4. Deploy Web Service

Compile and package the web service into a WAR file, and deploy it into a Java EE servlet container.

5. Test a Web Service

The deployed web service can be tested by accessing the generated WSDL document via the URL “http://<YOUR_HOST>/ws1-1.0-SNAPSHOT/ExamClouds?wsdl”.

6. Create a Web Service Client

The wsimport tool helps with creating soap web service client example in java:

wsimport -s src/main/java -p example.client -keep

7. Run the Client

And finally let's call the web service:

ExamCloudsImplService service = new ExamCloudsImplService();
ExamClouds port = service.getExamCloudsImplPort();


Read also: Лучшие онлайн курсы JavaТесты по Java с ответамиJava вопросы на собеседовании.