Consume SOAP Web Service using Web Service Consumer in Mule ESB

To consume a SOAP Web Service in the Mule ESB, in addition to using the CXF Component, we can also use the Web Service Consumer Connector. How is it in details? We will find out in this tutorial.

First, I will create a new Maven Mule project as an example:

Consume SOAP Web Service using Web Service Consumer in Mule ESB

In this example, I will use the HTTP Listener Connector to receive the request from the client with the name of the student (for example, my name as Khanh), then I will use the Web Service Consumer Connector to consume SOAP Web Service in the tutorial Expose SOAP Web Service using CXF component in Mule ESB, allow us to return the result of “Hello, Khanh”.

OK, let’s get started.

First, we will use the HTTP Listener Connector to expose a request to our application that allows the client to pass the student information.

Consume SOAP Web Service using Web Service Consumer in Mule ESB

If you do not know how to configure the HTTP Listener Connector, please refer to this tutorial.

Here, I configure as follows:

Consume SOAP Web Service using Web Service Consumer in Mule ESB

Global Configuration:

Consume SOAP Web Service using Web Service Consumer in Mule ESB

Next, you need to use the Transform Message Component to build the SOAP message.

Consume SOAP Web Service using Web Service Consumer in Mule ESB

Building SOAP message is a necessity for the SOAP Web Service to process our requests.

As I mentioned in my tutorial Learn about SOAP message, we have a lot of tags in a SOAP message and the <Body> tag is a mandatory tag. In Mule 3, the Web Service Consumer Connector will automatically use the payload to build the <Body> and the Mule Message Property to build the <Header> of SOAP message. With SOAP Web Service in the tutorial Expose SOAP Web Service using CXF component in Mule ESB, because the “hello” operation only has the section <Body>, so what we need to do is build the content of the tag <Body>.

Here we are using the Transform Message Component with DataWeave to transform the request from the client into the XML content which we need to send to the SOAP Web Service.

Expect the XML content we need to send to the SOAP Web Service in the tutorial Expose SOAP Web Service using CXF component in Mule ESB is:

so, my DataWeave will have the following content:

Consume SOAP Web Service using Web Service Consumer in Mule ESB

Finally, we will use the Web Service Consumer Connector by dragging and dropping into the Message Processor in our example.

Consume SOAP Web Service using Web Service Consumer in Mule ESB

The configuration for the Web Service Consumer is as follows:

Consume SOAP Web Service using Web Service Consumer in Mule ESB

In order to configure the Web Service Consumer, we have two parts to do:

  • First is the Global Configuration section, to configure this section, click the Add button next to the Connector Configuration field.

Consume SOAP Web Service using Web Service Consumer in Mule ESB

You need to specify the WSDL file defined for the SOAP Web Service in the WSDL Location field. If you already have a WSDL file in your project, then click on the … button to choose the WSDL file! This field also allows us to specify the WSDL file from a remote URL, so I will enter the URL of the SOAP Web Service in the tutorial Expose SOAP Web Service using CXF component in Mule ESB for simplicity.

Consume SOAP Web Service using Web Service Consumer in Mule ESB

As you can see, after entering the WSDL URL, the fields below including Service, Port, Address are automatically configured based on the contents of the WSDL file. The values in the Field, Port, and Address fields define the URL information that the client will use to request to the SOAP Web Service. You can refer to the tutorial Learn about WSDL file in SOAP Web Service to understand more.

OK, so we have configured the Global Configuration for Web Service Consumer Connector. Click OK button to close this window.

  • After configuring the Global Configuration section, you will see the main configuration section of the Web Service Consumer Connector that automatically selects Operation that the SOAP Web Service is defining.

That’s it!

Now try running the application and then asking for http://localhost:8082/hello?name=Khanh. The result will be:

Consume SOAP Web Service using Web Service Consumer in Mule ESB

5/5 - (1 vote)

Add Comment