Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Consuming SOAP Web Services Using Mule

DZone's Guide to

Consuming SOAP Web Services Using Mule

All you need to consume a SOAP-based public web service from Mule Anypoint Studio is a WSDL to locate the SOAP-based web service.

· Integration Zone ·
Free Resource

SnapLogic is the leading self-service enterprise-grade integration platform. Download the 2018 GartnerMagic Quadrant for Enterprise iPaaS or play around on the platform, risk free, for 30 days.

Mule's web service consumer is a ready-made connector that can connect to a SOAP service provider. All it needs is a WSDL to locate the SOAP-based web service.

1. Discover the SOAP Web Service

In order to consume a web service, we need to discover it first. We need to get the WSDL of the web service in order to consume it. For this example, we will use the temperature conversion web service hosted by w3schools. It is public and free to use. You can find it here.

This provides two operations for temperature conversion as shown below:

Operations Exposed by TempConvert W3School Webservice

2. Consume the SOAP Web Service Using Mule Studio

Mule Studio provides HTTP connector for reading the WSDL and extracting the metadata of the web service.

Create a new Mule project. Go to File > New > Mule Project.

Creating New Mule Project

Name the project as soap_webservice_consumer. Click Finish

On the canvas, drag an HTTP connector as shown below. Click HTTP Connector on the canvas to configure its properties. Below, next to the Console window, you can see HTTP properties window as well.

HTTP Configuration

In Properties window, keep the path as the default / and type Allowed Methods as GET.

Click the green + sign next to Connector Configuration dropdown. You can see the Global Elements Properties window pop up. Many fields are prepopulated. For now, we use the default host and port.

Setting HTTP host and port

Click OK. Now drag and drop a web service consumer from the Mule palette onto the canvas. Click Web Service Consumer to configure its properties. Below, you can see the Web Service Consumer properties window.

Web Service Consumer Properties

Click green + sign next to Connect Configuration. This will open a Global Element Properties window as shown below.

Getting wsdl metadata

Let's set WSDL Location with the value https://www.w3schools.com/xml/tempconvert.asmx?wsdl.

Service, port, and address are automatically populated by the Web Service Consumer Connector based on the value of WSDL location. If there are multiple services hosted on the same "location," then you can choose from the service drop-down accordingly.

Global Element Properties for Web Service Consumer

Back to the Mule design. You can see that Connector Configuration is set to the global Web_Service_Consumer element. 

Just below that, choose the operation that you want to call. In our case, the TempConvert exposes two operations: CelsiusToFahrenheit and FahrenheitToCelsius. Choose CelsiusToFahrenheit from dropdown as we will need to convert Celsius to Fahrenheit.

Choose operation in Web Service Consumer

Drag and drop a variable element from the Mule palette between HTTP and Web Service Consumer. This will capture the query parameter temp in the URL and assign it to FlowVar inputTemp as shown below:

Parsing Input Request

 Drag and drop a transform message from the Mule palette, after the variable. Assign inputTemp   to ns0:Celsius: String as shown below. This will set the input for the SOAP request, which will be sent to the web service.

Setting SOAP request

That's it! Let's send some requests to convert Celsius to Fahrenheit to the SOAP web service. Run the project.

Image title

Let's send a request to our mule flow using chrome. For this we will convert 34 degree Celsius to Fahrenheit.

Type localhost:8081/?temp=34 in the address bar and hit enter. We will get the SOAP response with the converted temperature in Fahrenheit.

Testing the application

We have successfully consumed a SOAP-based public web service from Anypoint Studio.

With SnapLogic’s integration platform you can save millions of dollars, increase integrator productivity by 5X, and reduce integration time to value by 90%. Sign up for our risk-free 30-day trial!

Topics:
tutorial ,integration ,mule ,web service ,soap ,wsdl

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}