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

Consume Multiple Operations of SOAP-Based Web Service With Mulesoft Anypoint Studio

DZone's Guide to

Consume Multiple Operations of SOAP-Based Web Service With Mulesoft Anypoint Studio

This followup tutorial will show you how to easily use Mulesoft Anypoint Studio to consume a SOAP service with more than one operation using a single flow.

· Integration Zone
Free Resource

Build APIs from SQL and NoSQL or Salesforce data sources in seconds. Read the Creating REST APIs white paper, brought to you in partnership with CA Technologies.

I am writing this article as an extension of this Mulesoft tutorial.

In this article, will talk about consuming different SOAP service operations in the same flow using Mule Choice flow control.

Consuming a SOAP-based web service is fairly simple in Mule Anypoint Studio. First, create a new Mule Project, then follow the following steps.

1. HTTP Listener

Use the HTTP Listener connector and drag it in your flow.

HTTP Listener

The HTTP listener configuration can be set to the default values as shown below:

Image title

2. Variable

Next, add a Variable to the flow. In our case, we will name it as "IP." For this article, we are using a public SOAP service which has two operations. The WSDL is available at http://www.webservicex.net/geoipservice.asmx?WSDL. One operation (GetGeoIP) returns the country name and country code of the IP address, which is supplied in the request. The second operation (GetGeoIPContext) returns the country name and country code for you, the consumer. The country code is in ISO Alpha-3 format.

Image title

The next step will do the trick of invoking two different operations (whether the same SOAP service or different) in the same flow. This is achieved by introducing a 'Choice' flow control after the variable. The Choice will allow the consumer to call the relevant SOAP service based on the input parameter we have set in the previous step, 'IP'.

Image title


As you can see, we have now introduced a Choice control flow with two conditions. If none of the conditions match, we will just log a message in the logger. Before you can set these conditions in the Choice Properties, you need to set up the 'Web Service Consumer' in your flow. Since we are consuming two operations, we will set up two web service consumers. 

We have mapped the flow variable 'IP' to the input of our service as the payload. The second service does not require any input. Therefore, there is no transform message step before the second web service consumer. 

3. Web Service Consumer

The next step is to add the web service consumer. While adding the consumer, we will set up the service configuration as shown below:

Image title

For consumer 1 (GetGeoIP), we will set up a 'Transform Message" step. This requires a value to passed across in the "IP" parameter when hitting the service.

Image title

Next, we configure our two consumers:

a. GetGeoIP

Image title

b. GetGeoIPContext

Image title

As the last step, you can also add XML to JSON to convert the final XML message into JSON.

4. Testing

We can test the service after deploying the application in Anypoint Studio. You can use a browser or Postman to hit the service.

1. GetGeoIP

Request:

http://localhost:8081/geoipservice?ip=8.8.8.8

Response:

{
"GetGeoIPResponse" : {
"@xmlns:xsd" : "http://www.w3.org/2001/XMLSchema",
"@xmlns:xsi" : "http://www.w3.org/2001/XMLSchema-instance",
"@xmlns:xmlns" : "http://www.webservicex.net/",
"GetGeoIPResult" : {
"ReturnCode" : "1",
"IP" : "8.8.8.8",
"ReturnCodeDetails" : "Success",
"CountryName" : "United States",
"CountryCode" : "USA"
}
}
}

2. GetGeoIPContext

Request: 

http://localhost:8081/geoipservice?ip

Response:

{
"GetGeoIPContextResponse" : {
"@xmlns:xsd" : "http://www.w3.org/2001/XMLSchema",
"@xmlns:xsi" : "http://www.w3.org/2001/XMLSchema-instance",
"@xmlns:xmlns" : "http://www.webservicex.net/",
"GetGeoIPContextResult" : {
"ReturnCode" : "1",
"IP" : "11.22.23.11",
"ReturnCodeDetails" : "Success",
"CountryName" : "France",
"CountryCode" : "FRN"
}
}
}

I hope this article helps you understand how to consume a SOAP service which has more than one operation in Mule Anypoint studio using a single flow.

The Integration Zone is brought to you in partnership with CA Technologies.  Use CA Live API Creator to quickly create complete application backends, with secure APIs and robust application logic, in an easy to use interface.

Topics:
mule ,mulesoft ,anypoint studio ,soap ,consumer ,flow ,geolocation

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}