Soap Web Service Java Example

Joyce Jul 13, 2026

Soap Web Services have been a stalwart in the world of web development, facilitating interoperability between different platforms and programming languages. Java, being a robust and versatile language, has excellent support for creating and consuming SOAP web services. Let's delve into a comprehensive guide on 'soap web service java example', exploring the creation and consumption of these services in Java.

SOAP Web Service in Java (JAX-WS)
SOAP Web Service in Java (JAX-WS)

Before we dive into the examples, it's crucial to understand that SOAP (Simple Object Access Protocol) is a messaging protocol that allows one application to communicate with another using a standardized XML format. Now, let's proceed with our Java-based SOAP web service example.

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

Creating a SOAP Web Service in Java

To create a SOAP web service in Java, we'll use the JAX-WS (Java APIs for XML Web Services) technology stack. The first step is to annotate our Java class with the necessary JAX-WS annotations.

Difference between SOAP and RESTful Web Service in Java
Difference between SOAP and RESTful Web Service in Java

Here's a simple example of a Java class annotated for a SOAP web service:

```java @WebService public class MyWebService { @WebMethod public String sayHello(String name) { return "Hello, " + name; } } ```

Deploying the Web Service

Client Challenge
Client Challenge

After creating the service, we need to deploy it. This can be done using a servlet container like Tomcat or GlassFish, which support JAX-WS. Here's how you can deploy the service in GlassFish:

  1. Create a WAR file containing your web service.
  2. Copy the WAR file to the 'glassfish/domains/domain1/autodeploy' directory.
  3. Start GlassFish. The web service will be automatically deployed and ready for use.

Consuming the Web Service

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

To consume the web service, we'll create a Java client that uses the service's WSDL (Web Services Description Language) to generate a proxy.

Here's how you can create a Java client for our 'sayHello' service:

```java MyWebService service = new MyWebServiceService().getMyWebServicePort(); String response = service.sayHello("World"); System.out.println(response); // prints "Hello, World" ```

Consuming a Third-Party SOAP Web Service

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

In this section, we'll consume a third-party SOAP web service, the popular 'Weather SOAP API' provided by 'OpenWeatherMap'.

Before proceeding, make sure to sign up for a free API key from 'OpenWeatherMap', which we'll use to authenticate our requests.

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
Exposing a SOAP service as a Managed REST API
Exposing a SOAP service as a Managed REST 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
Savon — Handmade Organic Soap Shopify Theme
Savon — Handmade Organic Soap Shopify Theme
CleanSkin | Handmade Organic Soap & Natural Cosmetics Shop WordPress Theme + Elementor
CleanSkin | Handmade Organic Soap & Natural Cosmetics Shop WordPress Theme + Elementor
the website for sushibee is displayed in green and white colors, with flowers on it
the website for sushibee is displayed in green and white colors, with flowers on it
Natural Handmade Soap Website Design Ideas
Natural Handmade Soap Website Design Ideas
Spring Restful Web Services Json Example - Java2Blog
Spring Restful Web Services Json Example - Java2Blog
Soapy - Landing Page
Soapy - Landing Page
java basics
java basics
E-commerce on shopify | retro website design
E-commerce on shopify | retro website design
☕ Java Basics Cheat Sheet for Beginners | Learn Java in One Page 🚀
☕ Java Basics Cheat Sheet for Beginners | Learn Java in One Page 🚀
Soap Ads, Coffee Soap, Glowing Skin Routine, Soap For Sensitive Skin, Exfoliating Body Scrub, Rose Essential Oil, Ayurvedic Herbs, Sls Free Products, Organic Soap
Soap Ads, Coffee Soap, Glowing Skin Routine, Soap For Sensitive Skin, Exfoliating Body Scrub, Rose Essential Oil, Ayurvedic Herbs, Sls Free Products, Organic Soap
the website design for spa and beauty products
the website design for spa and beauty products
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
Freesia - Handmade Soap - Minh Gia
Freesia - Handmade Soap - Minh Gia
How to design a simple dashboard UI using Swing and Java -Netbeans
How to design a simple dashboard UI using Swing and Java -Netbeans

Creating the Service Reference

The first step is to create a service reference in our Java project, which will generate the necessary proxy classes and configuration files. Here's how:

  1. In your Java project, right-click and select 'Service Reference...'.
  2. Enter the WSDL URL (https://www.openweathermap.org/current) and click 'Go'.
  3. Complete the Reference Details and click 'Finish'.

Using the Web Service

Once the service reference is created, we can use the generated classes to make API calls. Here's how:

```java CurrentWeather response = weatherService.getCurrentWeatherByName("London", "imperial", "appid=YOUR_API_KEY"); System.out.println("Temperature: " + response.getMain().getTemp() + "°F"); ```

Remember to replace 'YOUR_API_KEY' with the API key you obtained from OpenWeatherMap.

That's it! We've successfully created and consumed SOAP web services in Java. As the final stepping stone, always keep your web services secure by implementing authentication and authorization mechanisms.

"