Java EE SOAP Web Service Example

Joyce Jul 13, 2026

Java EE SOAP web services are integral components in enterprise-level applications, enabling secure and efficient remote communication. Let's explore how to create a simple Java EE SOAP web service example using JAX-WS, the Java API for XML-based web services.

How to send SOAP Requests using the Postman Client? | SOAP Web Services | Web Services Tutorial
How to send SOAP Requests using the Postman Client? | SOAP Web Services | Web Services Tutorial

First, we'll set up the project structure and dependencies. For this example, we'll use Maven as our build tool and add the necessary dependencies to our pom.xml file:

Difference Between REST and SOAP
Difference Between REST and SOAP

Project Setup and Dependencies

To get started, we need to configure our project's environment and include the required dependencies. In your pom.xml file, ensure you have the following:

a diagram showing the different types of servers and their respective services, including servers
a diagram showing the different types of servers and their respective services, including servers

Maven Dependencies

Add these dependencies to your pom.xml file to set up a Java EE SOAP web service project:

7 Best Handmade Soap WooCommerce Theme 2026
7 Best Handmade Soap WooCommerce Theme 2026

```xml javax.ws.rs javax.ws.rs-api 2.1 javax.annotation javax.annotation-api 1.3.2 javax.xml.bind jakarta.xml.bind-api 2.3.2 ```

The above dependencies cover JAX-WS, JAX-RS, and JAXB, which are crucial for creating and consuming SOAP web services in Java EE.

Create a Web Service

Now, let's create a simple SOAP web service with a single method. By convention, web services in Java EE are deployed as EJBs (Enterprise JavaBeans):

Natural Handmade Soap Website Design Ideas
Natural Handmade Soap Website Design Ideas

```java import javax.jws.WebMethod; import javax.jws.WebService; @WebService public class GreetingService { @WebMethod(operationName="sayHello") public String sayHello(String name) { return "Hello, " + name + "!"; } } ```

The @WebService annotation indicates that this EJB class should be exposed as a web service, and the @WebMethod annotation marks the method to be included in the WSDL (Web Services Description Language).

Deploying and Testing the Web Service

Once you've compiled and packaged your project as a WAR (Web ARchive) file, deploy it to your application server (e.g., GlassFish, WildFly) to expose your web service. After deployment, you can test the service using a SOAP client tool like SoapUI or a simple Java client using the JAX-WS API:

the website is designed to look like it has many different desserts on it
the website is designed to look like it has many different desserts on it

Java Client for Testing

To test our deployed web service, we'll create a simple Java client:

Handmade Soap Business Website for Small Brands
Handmade Soap Business Website for Small Brands
Natural Handmade Soap Website Design Ideas
Natural Handmade Soap Website Design Ideas
CleanSkin | Handmade Organic Soap & Natural Cosmetics Shop WordPress Theme + Elementor
CleanSkin | Handmade Organic Soap & Natural Cosmetics Shop WordPress Theme + Elementor
the shop page is clean and ready to be used for products, such as soaps
the shop page is clean and ready to be used for products, such as soaps
the website design for spa and beauty products
the website design for spa and beauty products
☕ Java Basics Cheat Sheet for Beginners | Learn Java in One Page 🚀
☕ Java Basics Cheat Sheet for Beginners | Learn Java in One Page 🚀
E-commerce on shopify | retro website design
E-commerce on shopify | retro website design
Service Page - Waste Disposal Services React Next JS Template Wastix - Waste Disposal Services React
Service Page - Waste Disposal Services React Next JS Template Wastix - Waste Disposal Services React
Savon — Handmade Organic Soap Shopify Theme
Savon — Handmade Organic Soap Shopify Theme
Soapy - Landing Page
Soapy - Landing Page
Abstraction in Java - Learn with its Types and Real-life Examples - TechVidvan
Abstraction in Java - Learn with its Types and Real-life Examples - TechVidvan
Shopify Website Handmade Soap Business
Shopify Website Handmade Soap Business
the shop page is clean and ready to be used for products, such as soaps
the shop page is clean and ready to be used for products, such as soaps
Woocommerce Website
Woocommerce Website
✨Modern Beauty & Skincare Website UI Design ✨
✨Modern Beauty & Skincare Website UI Design ✨
Freesia - Handmade Soap - Minh Gia
Freesia - Handmade Soap - Minh Gia
Etsy Isn’t Enough for Handmade Soap Sellers
Etsy Isn’t Enough for Handmade Soap Sellers
Do My Java Assignment? Here's What Actually Works for CS Students at 2 AM
Do My Java Assignment? Here's What Actually Works for CS Students at 2 AM
Java VS JavaScript
Java VS JavaScript
Soap Making Software for Soapmakers
Soap Making Software for Soapmakers

```java import javax.xml.ws.*; public class WebServiceClient { public static void main(String[] args) throws MalformedURLException { Service service = Service.create(new URL("http://localhost:8080/ws-example/ jealousSvc?WSDL")); GreetingService greetingService = service.getPort(GreetingService.class); System.out.println(greetingService.sayHello("World")); } } ```

Replace http://localhost:8080/ws-example/jealousSvc?WSDL with your web service's WSDL URL.

SoapUI for Testing

Alternatively, you can use tools like SoapUI to test your web service. Follow these steps to import and test your WSDL using SoapUI:

  1. Open SoapUI, click on New SOAP Project, and then click on the Import from WSDL button.
  2. Enter your WSDL URL (e.g., http://localhost:8080/ws-example/jealousSvc?WSDL) and click OK.
  3. In the GreetingService endpoint, enter a name and run the sayHello operation.

Having explored the fundamentals of creating and testing a Java EE SOAP web service, you're now ready to build more complex and powerful web services using SOAP and JAX-WS in your enterprise applications.