Java Axis2 SOAP Client Tutorial: Step-by-Step Example

Joyce Jul 13, 2026

Java developers often need to integrate SOAP web services into their applications. Axis2 is a popular choice for creating and consuming these services. In this guide, we'll create a simple Java Axis2 SOAP client example, demonstrating how to initiate a SOAP request and parse the response.

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

Before we dive in, ensure you have Apache Axis2 and Java installed. You'll also need the axis2/Java-2.3.6.zip for the samples provided here.

soap bars stacked on top of each other with different colors and shapes in the middle
soap bars stacked on top of each other with different colors and shapes in the middle

Setting Up Your Project and Dependencies

Let's start by setting up your project and adding required dependencies. If you're using Maven, add the following to your pom.xml:

4 Science-Backed Benefits of Natural & Organic Soap  Here are the five proven benefits that e...
4 Science-Backed Benefits of Natural & Organic Soap Here are the five proven benefits that e...

<dependency>
    <groupId>org.apache.axis2</groupId>
    <artifactId>axis2</artifactId>
    <version>1.6.3</version>
</dependency>

Creating the Client Configuration Context

Handmade Soap Business, Eco-friendly Soap Packaging Tips, Cold Process Soap Packaging, Small Soap Business, Handmade Soap Stickers, Soap Samples, 100% Natural Soap, Soap Cold Process Recipe, Home-based Soap Business Ideas
Handmade Soap Business, Eco-friendly Soap Packaging Tips, Cold Process Soap Packaging, Small Soap Business, Handmade Soap Stickers, Soap Samples, 100% Natural Soap, Soap Cold Process Recipe, Home-based Soap Business Ideas

First, create a client configuration context to set up your endpoint:

OMElement response;
ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContext();
configContext.getConfiguration().setMaxMessageSize(400000);
configContext.getConfiguration().getAxisServices().clear();
EndpointReference targetEPR = new EndpointReference("http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL");
ServiceClient serviceClient = new ServiceClient(configContext, targetEPR);

Invoking the Web Service

Soap isn’t the villain. The chemicals in it are. Camia’s soaps are made the old way — with shea butter, coconut oil, and essential oils. So they cleanse, hydrate, and leave skin happy.  [cold process soap India, shea butter soap, handmade soap benefits, sulfate free bar soap, camia] Soap Benefits, Bar Soap Benefits, Soap Facts, Soap Quotes, Soap Advertising, Ads For Soap, Soap Ads Creative, Natural Soap Advertisement, Soap Ads
Soap isn’t the villain. The chemicals in it are. Camia’s soaps are made the old way — with shea butter, coconut oil, and essential oils. So they cleanse, hydrate, and leave skin happy. [cold process soap India, shea butter soap, handmade soap benefits, sulfate free bar soap, camia] Soap Benefits, Bar Soap Benefits, Soap Facts, Soap Quotes, Soap Advertising, Ads For Soap, Soap Ads Creative, Natural Soap Advertisement, Soap Ads

Now, let's create a SOAP request and invoke the web service:

OMFactory factory = configContext.getOMFactory();
OMElement weatherRequest = factory.createOMElement("GetWeatherByZIP", null);
OMElement zipCode = factory.createOMElement("ZIPCode");
zipCode.setText("90210");
weatherRequest.addChild(zipCode);
response = serviceClient.sendReceive(weatherRequest);

Parsing the SOAP Response

two hands are holding a soap bar with labels on it and labeled in the words yoki
two hands are holding a soap bar with labels on it and labeled in the words yoki

The response is an OMElement, which can be parsed using the following code:

if (response != null) {
    Iterator iter = response.getChildren();
    while (iter.hasNext()) {
        OMElement elem = (OMElement) iter.next();
        System.out.println(elem.getLocalName() + ": " + elem.getText());
    }
}

coffee scrub soap recipe with instructions on how to use it
coffee scrub soap recipe with instructions on how to use it
EcoRoots on Instagram: “Face + Body Soaps are BACK IN STOCK! 🧼 Our bars are handmade in small batches without synthetic fragrances, colorants, parabens, sulfates,…” Organic Soap Photography, Silk African Black Soap, Soap Bar Product Photography, Face Bar Soap, Soap Photoshoot, Bar Soap Photography, African Black Soap Bar, Soap Model Photography, Organic Soap Photo
EcoRoots on Instagram: “Face + Body Soaps are BACK IN STOCK! 🧼 Our bars are handmade in small batches without synthetic fragrances, colorants, parabens, sulfates,…” Organic Soap Photography, Silk African Black Soap, Soap Bar Product Photography, Face Bar Soap, Soap Photoshoot, Bar Soap Photography, African Black Soap Bar, Soap Model Photography, Organic Soap Photo
Cedarwood + Tea Tree Organic Shea Butter Grounding Soap
Cedarwood + Tea Tree Organic Shea Butter Grounding Soap
a box filled with different types of soaps on top of a table next to flowers
a box filled with different types of soaps on top of a table next to flowers
several different types of soaps sitting on top of each other in front of newspaper pages
several different types of soaps sitting on top of each other in front of newspaper pages
Commercial Soap Vs Natural Soap, Difference Between Commercial Soap And Natural Soap, Difference Between Natural Soap And Commercial Soap, Natural Soap Vs Commercial Soap, What's The Difference Between Commercial Soap And Natural Soap, Soap Vs Detergent Benefits, Types Of Soap, How To Choose Neutral Soap, Natural Soap Dilution Guide
Commercial Soap Vs Natural Soap, Difference Between Commercial Soap And Natural Soap, Difference Between Natural Soap And Commercial Soap, Natural Soap Vs Commercial Soap, What's The Difference Between Commercial Soap And Natural Soap, Soap Vs Detergent Benefits, Types Of Soap, How To Choose Neutral Soap, Natural Soap Dilution Guide
the shelves are filled with different types of items
the shelves are filled with different types of items
Soap sample idea! Printed and cut at home. #soapmaking #diy #howto
Soap sample idea! Printed and cut at home. #soapmaking #diy #howto
Client Challenge
Client Challenge
EXCITING NEWS❕❕❕ You can find our soap on @amazonhandmade ! All soaps are listed on Amazon for SALE! Sale lasts until 11/30/24 🫶🏻 You still get all the packaging goodies like samples, a sticker, a soap care guide, and an overall enjoyable unboxing experience! Everything pictured can be found on our Amazon handmade store! Christmas soaps are exclusively sold on our website www.evidentsoap.com ❤️🎄🫧 You can find the direct link to our amazon store from the link our bio 🧼 HURRY before th... Traditional Soap Making, Soap Business Packaging, Handmade Soap Labels, Handmade Soap Business, Eco-friendly Soap Packaging Tips, Cold Process Soap Packaging, Small Soap Business, Affordable Soap Making Kit, Handmade Soap Stickers
EXCITING NEWS❕❕❕ You can find our soap on @amazonhandmade ! All soaps are listed on Amazon for SALE! Sale lasts until 11/30/24 🫶🏻 You still get all the packaging goodies like samples, a sticker, a soap care guide, and an overall enjoyable unboxing experience! Everything pictured can be found on our Amazon handmade store! Christmas soaps are exclusively sold on our website www.evidentsoap.com ❤️🎄🫧 You can find the direct link to our amazon store from the link our bio 🧼 HURRY before th... Traditional Soap Making, Soap Business Packaging, Handmade Soap Labels, Handmade Soap Business, Eco-friendly Soap Packaging Tips, Cold Process Soap Packaging, Small Soap Business, Affordable Soap Making Kit, Handmade Soap Stickers
an advertisement for charcoal and oat milk soap on a white plate with ingredients in it
an advertisement for charcoal and oat milk soap on a white plate with ingredients in it
a bar of soap sitting on top of a wooden table
a bar of soap sitting on top of a wooden table
Hot Process Soap Recipes, Natural Hand Soap, Homemade Soap Recipes, Chemical Reactions, Craft Room Organization, Diy Creative Crafts, Diy Soap, Soap Recipes, Home Spa
Hot Process Soap Recipes, Natural Hand Soap, Homemade Soap Recipes, Chemical Reactions, Craft Room Organization, Diy Creative Crafts, Diy Soap, Soap Recipes, Home Spa
three soap bars with flowers on them sitting next to each other in front of a white background
three soap bars with flowers on them sitting next to each other in front of a white background
Soap Instructions, Soap Labeling, Eco-friendly Soap Packaging Tips, Soap Marketing, Soap Business Packaging, Soap Format, Soap Template, Natural Soap Labels, Soap Label
Soap Instructions, Soap Labeling, Eco-friendly Soap Packaging Tips, Soap Marketing, Soap Business Packaging, Soap Format, Soap Template, Natural Soap Labels, Soap Label
some pink flowers are sitting on a table
some pink flowers are sitting on a table
Soap for every member of your family👪
Soap for every member of your family👪
three pieces of soap sitting on top of a wooden tray
three pieces of soap sitting on top of a wooden tray
soap vs handmade soap which is better for you? infographical poster on wood background
soap vs handmade soap which is better for you? infographical poster on wood background
Natural Diy, Soap Making, Soap
Natural Diy, Soap Making, Soap

Error Handling

Don't forget to handle exceptions that may occur during service invocation:

try {
    // Your code here
} catch (AxisFault axisFault) {
    axisFault.printStackTrace();
}

Shutdown the Client

After you're done, don't forget to shut down the client:

serviceClient.cleanupTransport();
serviceClientCleanup(configContext);

That's it! You've created a simple Java Axis2 SOAP client. This example demonstrates getting weather data based on a zip code, but you can replace the 'GetWeatherByZIP' method with any other web service operation you need.

Now, go ahead and build more functionalities upon this baseline. Happy coding!