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.
Join the DZone community and get the full member experience.
Join For FreeI 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.
The HTTP listener configuration can be set to the default values as shown below:
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.
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'.
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:
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.
Next, we configure our two consumers:
a. GetGeoIP
b. GetGeoIPContext
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.
Opinions expressed by DZone contributors are their own.
Trending
-
Understanding Dependencies...Visually!
-
Competing Consumers With Spring Boot and Hazelcast
-
Microservices With Apache Camel and Quarkus (Part 3)
-
Health Check Response Format for HTTP APIs
Comments