Expose SOAP Web Service using APIkit SOAP in Mule 4

I showed you how to expose SOAP Web Service using APIkit SOAP in Mule 3, APIkit SOAP in Mule 4 is different, from the way that we put the .wsdl file until the way we build the response to return back to the user. How is it in details? Let’s find out together in this tutorial!

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

Expose SOAP Web Service using APIkit SOAP in Mule 4

I will use the file hello.wsdl with the following content as an example:

In Mule 4, all resource files should be in the src/main/resources directory and for files that define REST or SOAP APIs, they should be in the available api directory so I won’t put the file hello.wsdl is in src/main/wsdl directory as in Mule 3:

Expose SOAP Web Service using APIkit SOAP in Mule 4

Now we will generate the Mule Flows from this .wsdl file!



Similar to Mule 3, you must also right-click the file hello.wsdl then select Mule and then select “Generate Flows from WSDL”, the following window will also appear:

Expose SOAP Web Service using APIkit SOAP in Mule 4

You can also leave the default and click OK as in Mule 3!
Then, you will also see the Mule Flows generated as follows:

Expose SOAP Web Service using APIkit SOAP in Mule 4

As you can see, similar to Mule 3, Anypoint Studio 7 also generated Mules Flows using SOAP API with an api-main Mule Flow will receive requests from the client and each SOAP Web Service operation will be generated into one Mule Flow. Our task is also to implement Mule Flow for each operation is done.

By default, the Mule Flow for each operation has only one endpoint Transform Message. The content of this Transform Message endpoint will depend on the operation of SOAP Web Service that will have different content. In this example, the content of the endpoint Transform Message for the hello operation is as follows:

You can remove this endpoint Transform Message to implement this Mule Flow in your own way, but you must comply with the definition of the WSDL file.

I will edit the endpoint Transform Message of the hello operation to build the SOAP response message return to the client with the following content:

As you can see, different from Mule 3, the <Body> section and the <Header> section of the SOAP response message in Mule 4 will be converted from Payload content and no longer separate. And when the client request arrives, the content of the SOAP message is also encapsulated in the Mule’s Payload Message!



By default, when generating the Mule Flows from the .wsdl file, the HTTP Listener Connector section will have the following default configuration:

Expose SOAP Web Service using APIkit SOAP in Mule 4

Global Element Properties:

Expose SOAP Web Service using APIkit SOAP in Mule 4

To match with the definition of hello.wsdl file, I will modify the Path section’s value to “/hello” as follows:

Expose SOAP Web Service using APIkit SOAP in Mule 4

Now, we have completed a simple example to expose SOAP Web Service using the SOAP APIkit in Mule 4!

The results of my example will be as follows:

Expose SOAP Web Service using APIkit SOAP in Mule 4

5/5 - (1 vote)

Add Comment