Step 1: Open Eclipse IDE, Create a Maven Project, Check – Create a simple project (skip archetype selection) and Click Next.

Step 2: In New Maven Project window add the following details – Group id: com.example, Artifact Id: SimpleSOAPService and Version: 0.0.1- SNAPSHOT and click Finish

Step 3: After creating the Maven project, update the pom.xml to include the necessary dependencies for Apache CXF and JAX-WS. 

Here’s the full pom.xml file:
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example</groupId>
  <artifactId>SimpleSOAPService</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>
        <!-- Apache CXF for JAX-WS -->
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>3.4.5</version>
        </dependency>

        <!-- Apache CXF HTTP Transport -->
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>3.4.5</version>
        </dependency>

        <!-- Apache CXF HTTP Jetty Transport (for embedded HTTP server) -->
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http-jetty</artifactId>
            <version>3.4.5</version>
        </dependency>

        <!-- Jakarta XML WS (JAX-WS API) -->
        <dependency>
            <groupId>jakarta.xml.ws</groupId>
            <artifactId>jakarta.xml.ws-api</artifactId>
            <version>2.3.3</version>
        </dependency>

        <!-- Java Annotations -->
        <dependency>
            <groupId>javax.annotation</groupId>
            <artifactId>javax.annotation-api</artifactId>
            <version>1.3.2</version>
        </dependency>
    </dependencies>
</project>

	

Step 4: Create the Service Interface
Now, create a simple SOAP service interface to define the operations.
1.	Right-click on src/main/java → New → Package and name it com.example

1.	Right-click on the com.example package → New → Class and name it CalculatorService.java.

File Name: CalculatorService.java

Code:
package com.example;

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public interface CalculatorService {
	@WebMethod
	int add(int num1, int num2);

	@WebMethod
	int subtract(int num1, int num2);
}




Step 5: Implement the Service
Now, create a class that implements the CalculatorService interface.
1.	Right-click on com.example → New → Class and name it CalculatorServiceImpl.java.
2.	Add the following code to 

CalculatorServiceImpl.java:

package com.example;

import javax.jws.WebService;

@WebService(endpointInterface = "com.example.CalculatorService")
public class CalculatorServiceImpl implements CalculatorService {

    @Override
    public int add(int num1, int num2) {
        return num1 + num2;
    }
    @Override
    public int subtract(int num1, int num2) {
        return num1 - num2;
    }
}

Step 6: Create the SOAP Server
Next, create a class to publish the SOAP service.
1.	Right-click on com.example → New → Class and name it SOAPServer.java.
2.	Add the following code to SOAPServer.java:

File Name: SOAPServer.java
package com.example;

import javax.xml.ws.Endpoint;

public class SOAPServer {
    public static void main(String[] args) {
        CalculatorServiceImpl calculatorService = new CalculatorServiceImpl();
        String address = "http://localhost:8080/CalculatorService";
        Endpoint.publish(address, calculatorService);
        System.out.println("SOAP Service started at " + address);
    }
}


Run the SoAp project

mvn clean install: The clean install command is commonly used in Maven to build and install a project. The purpose of running clean is to remove any previously compiled code or artifacts, ensuring that the next build starts fresh without using any old files that might cause conflicts or errors.
 

In Goal type clean install and run


Run the Application
1.	Right-click on SOAPServer.java → Run As → Java Application.
2.	You should see the following output:

SOAP Service started at http://localhost:8080/CalculatorService




Open SOAP UI
Step 7. Test the SOAP Service Using SOAPUI

1.	Open SOAPUI and create a new SOAP project:
1.	Click File → New SOAP Project.
2.	In the Project Name field, enter CalculatorService.
3.	In the Initial WSDL field, enter: http://localhost:8080/CalculatorService?wsdl


now on left double click add then double click Request1
windows opens
change ? marks to inputs then run using that green play button
then on left side click on XML
then u can see response that will be operation performed on input


