This article is the continued part in the MuleSoft articles series; if you would like to understand the basics of MuleSoft, refer to these articles before going next:
What is SOAP WS?
SOAP (Simple Object Access Protocol) is a protocol for exchanging structured information in the implementation of web services. It is a messaging protocol that allows programs running on different operating systems to communicate with each other by using XML as the message format. Unlike REST, SOAP is a protocol, and it defines a set of rules for structuring messages, specifying how they are sent and received.
Key characteristics of SOAP web services
Key characteristics of SOAP web services include.
- XML-Based Messaging: SOAP messages are typically encoded in XML format. XML provides a standardized way to structure data, making it readable by both humans and machines.
- Protocol Independence: SOAP can be used with various transport protocols, including HTTP, SMTP, and more. However, it is most associated with HTTP and is used for web-based communication.
- Service Description: Web services using SOAP often provide a formal description of their functionality using WSDL (Web Services Description Language). WSDL defines the methods, parameters, and data types that can be used to interact with the service.
- Stateful or Stateless Communication: SOAP itself is a stateless protocol, meaning that each request from a client to a server is independent. However, web services built on top of SOAP may implement stateful communication if needed.
- Error Handling: SOAP provides a standardized way to handle errors and exceptions, making it suitable for applications where reliable and comprehensive error reporting is essential.
- Security: SOAP has built-in support for security features such as encryption and digital signatures. This makes it a suitable choice for applications where data security is a critical concern.
- Complex Operations: SOAP supports complex operations and transactions, making it suitable for enterprise-level applications where a high level of reliability and consistency is required.
SOAP web services are commonly used in enterprise-level applications, especially in scenarios where the exchange of structured and complex data is essential. They are often favored in situations where the application needs a strict and standardized communication protocol. However, the verbosity of XML and the complexity of the protocol have led to the popularity of RESTful web services, which are simpler and more lightweight in many cases.
When working with SOAP, developers use tools like WSDL to describe the web service interface and libraries or frameworks (e.g., Apache CXF, JAX-WS) to generate the necessary code for interacting with the service.
Sample WSDL File
I am going to use a sample Calculator WSDL file calling the Add two number function and supply two inputs.
WSDL: Web Service Description Language, is an XML-based definition language. It’s used for describing the functionality of a SOAP based web service.
http://www.dneonline.com/calculator.asmx?wsdl
Getting Started with Anypoint Studio
Let's do a quick project setup and include the required global config files; these are the quick steps:
First, open Anypoint Studio and Create a New Mule Project.
Enter the project name, select runtime and project location, and click the Finish button.
Next, add a New Mule Configuration file for global settings.
Give the file name global and click Finish.
Next, go to the global.xml file, click on the Global Elements tab, click the Create button, select HTTP Listener config and click OK.
Enter the required details like listener name, protocol, host, and port. I am keeping everything as default and clicking OK.
Drag and drop HTTP Listener from HTTP Palette to Message Flow, provide the display name, select global connector config, and provide endpoint path.
Before jumping into the Consume part, let's add two Set Variables and Transform Message controls.
Drag and drop two Set Variable from the Core Module.
Assign query parameter value as in var1.
Now add another set of variable controls.
Next, let’s drag and drop a Transform Message (Core) and map the variables with soap service variables.
Next, click on + Add Modules in Mule Palette, search for Web Service Consumers and Drag and drop from Featured to Palette.
After drag and drop, you will see the Web Service Consumer >> Consume component.
After drag and drop, you will see the Web Service Consumer >> Consume component.
Provide Web Service Consumer Config settings and give Wsdl settings.
At last, drag and drop the Set payload from the Core module and return the result.
Let's run the application to see the result; right-click on the file and click Run as Mule Application. Once you see the message Deployed, everything is good, and the application is deployed.
Open Postman to see the result and enter the request endpoint to see the result.
Enter the endpoint, hit the Send button, and see the status 200 and the result returned.
Conclusion
In this article, we learned how to involve SOAP Web Service in the Mule application and how to see the result in Postman.