Expose SOAP Web Service using APIkit SOAP in Mule ESB

In addition to using the CXF Component to expose a SOAP Web Service, we can also use the APIkit SOAP together with a WSDL file to do this in the Mule ESB. How is it in details? Let’s find out in this tutorial.

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

Expose SOAP Web Service using APIkit SOAP in Mule ESB

The WSDL file defined for the SOAP Web Service we use in this example is as simple as:

This WSDL defines a SOAP Web Service with an operation named “hello” that allows the user to send a SOAP message containing the name of someone in the <Body> section (for example, my name, Khanh). The <Header> section of the request message will contain the clientId information of the device sending the message. Implementation of the response section, which we will use the ESAP SOAP APIkit to do, is because of us. I will build to respond to the message “Hello, Khanh” for simplicity.



I will put this file into the /src/main/wsdl directory of the project.

In fact, this /src/main/wsdl directory is actually available when we create a new Mule Maven project but by default, it is not included as the project’s resource folder so you don’t see it. You can use the Builder Helper Maven Plugin plugin which is being declared in the pom.xml file of this project to include the wsdl folder as a resource folder as follows:

Then you will see the wsdl directory included as the source folder of the project.

Expose SOAP Web Service using APIkit SOAP in Mule ESB

Please put our wsdl file into this folder.

Expose SOAP Web Service using APIkit SOAP in Mule ESB



OK, now let’s go to the main topic of this tutorial.

To use the APIkit SOAP in Mule ESB, first, we need to declare its dependencies. There are 3 dependencies we need to declare for the APIkit SOAP:

Currently, I could not find the Maven repository that contains these three dependencies on the internet, so there is only one way that we will go to the plugins folder of Anypoint Studio and look for the org.mule.tooling.soapkit.contribution_1.1.4/lib directory

Expose SOAP Web Service using APIkit SOAP in Mule ESB

to get these files, then install them into the Local Maven repository. You can see the guideline for installing dependencies into the Local Maven repository here.

OK, after adding the dependencies, right-click on the hello.wsdl file in the example project and select Mule, then select Generate Flows from WSDL.

Expose SOAP Web Service using APIkit SOAP in Mule ESB

At this point, a window will appear:

Expose SOAP Web Service using APIkit SOAP in Mule ESB

allow us to choose the Mule Configuration file to generate Mule Flows.

You can leave the defaults and click the OK button.

You will see that Mule Flows is generated as follows:

Expose SOAP Web Service using APIkit SOAP in Mule ESB

As you can see, Anypoint Studio has generated Mule Flows using the APIkit SOAP with an api-main Mule flow will receive requests from the client, each SOAP Web Service operation will be generated as a Mule Flow. Our task is to implement the Mule flow for each operation.

By default, the flow mule for each operation has only one endpoint Set Payload. The content of this Set Payload endpoint depends on the operation of the SOAP Web Service, which will have different content. In this example, the content of the Set Payload endpoint is as follows:

You can remove this Set Payload endpoint to implement this flow in your own way but must conform to the definition of your WSDL file.



Here, I will delete this Set Payload endpoint and add a Transform Message Component to build the SOAP response message back to the client as follows:

Expose SOAP Web Service using APIkit SOAP in Mule ESB

Similar to the Web Service Consumer connector, the Payload part of the Mule Message will automatically convert the <Body> element of the SOAP response message.
To build the <Header> section for the response, we need to take another step, which is to build a Mule Message Property with a name that begins with “soap.”

To do this, in the Transform Message window, next to the Output of Payload, click on the new Target button:

Expose SOAP Web Service using APIkit SOAP in Mule ESB

A new window will appear:

Expose SOAP Web Service using APIkit SOAP in Mule ESB

Please select Output and enter Variable name as above.

Click the OK button to start building the Mule Message Property “soap.header”:

Expose SOAP Web Service using APIkit SOAP in Mule ESB

DataWeave content of the Message Property section “soap.header” will look like this:



You will now see the endpoint of the HTTP Listener Connector being corrupted. The cause is that after generating from the WSDL file, the Global Configuration of this connector has not been created. Please configure it, can see the guideline here.

Here, I configured the Global Configuration for the HTTP Listener Connector as follows:

Expose SOAP Web Service using APIkit SOAP in Mule ESB

Change the configuration of the HTTP Listener Connector to the correct definition of the WSDL file:

Expose SOAP Web Service using APIkit SOAP in Mule ESB

Here we have completed a simple example using the SOAP API to expose the SOAP Web Service, but to get our application running, you need to take more step to bring the SOAP API library into our application when running it with Mule Runtime. If you do not do this, you will get an error regarding the SOAP API’s mule-apikit-soap.xsd. With this last step, you need to open the pom.xml file and find the mule-app-maven-plugin plugin to include the SOAP API libraries as follows:

OK, that’s all, let run our application now.

Results when running with SOAPUI:

Expose SOAP Web Service using APIkit SOAP in Mule ESB

12 thoughts on “Expose SOAP Web Service using APIkit SOAP in Mule ESB

  1. Suppose, I have a HTTP Request connector after Transform message. And in case the target URL is down, I want to catch that exception and form a custom SOAP fault and send it back to the SOAPUI. How do I achieve this?

  2. POC1:

    (Create Salesforce developer account; Any point account)

    Implement a SOAP API with two resources. One is to get account detail from salesforce by account id & another one is to delete.
    Implement a REST API which should act as a wrapper / pass through service for SOAP.
    Should accept account id in path parameter
    Use appropriate HTTP method for resources
    Should return JSON response
    i. Account detail for get operation

    ii. and delete confirmation message for delete operation.

    Implement proper exception handling

    Please let me know how to implement a soap web service as per the above requirement?

    1. You should use Salesforce connector for calling and manipulating with Salesforce. Let define REST API with APIkit Router and implement the calling to SF for each resource. You should research more about SF to understand about it.

      Best regards,

  3. HI Khanh Nguyen, i was trying to create a Mule project to expose a soap service as above and while deploying the project i’m getting an error as below. I’m using Mule 3.9.0 Run-time.

    org.mule.module.launcher.DeploymentException: Failed to deploy artifact [helloservicesoapkit]
    at org.mule.module.launcher.DefaultArtifactDeployer.deploy(DefaultArtifactDeployer.java:85) ~[mule-module-launcher-3.9.1.jar:3.9.1]
    at org.mule.module.launcher.DefaultArchiveDeployer.deployArtifact(DefaultArchiveDeployer.java:547) ~[mule-module-launcher-3.9.1.jar:3.9.1]
    at org.mule.module.launcher.DefaultArchiveDeployer.deployArtifact(DefaultArchiveDeployer.java:325) ~[mule-module-launcher-3.9.1.jar:3.9.1]
    at org.mule.module.launcher.DefaultArchiveDeployer.deployPackagedArtifact(DefaultArchiveDeployer.java:185) ~[mule-module-launcher-3.9.1.jar:3.9.1]
    at org.mule.module.launcher.DefaultArchiveDeployer.deployPackagedArtifact(DefaultArchiveDeployer.java:274) ~[mule-module-launcher-3.9.1.jar:3.9.1]
    at org.mule.module.launcher.DefaultArchiveDeployer.deployPackagedArtifact(DefaultArchiveDeployer.java:80) ~[mule-module-launcher-3.9.1.jar:3.9.1]
    at org.mule.module.launcher.DefaultArchiveDeployer.deployPackagedArtifact(DefaultArchiveDeployer.java:577) ~[mule-module-launcher-3.9.1.jar:3.9.1]
    at org.mule.module.launcher.DeploymentDirectoryWatcher.deployPackedApps(DeploymentDirectoryWatcher.java:283) ~[mule-module-launcher-3.9.1.jar:3.9.1]
    at org.mule.module.launcher.DeploymentDirectoryWatcher.start(DeploymentDirectoryWatcher.java:155) ~[mule-module-launcher-3.9.1.jar:3.9.1]
    at org.mule.module.launcher.MuleDeploymentService.start(MuleDeploymentService.java:135) ~[mule-module-launcher-3.9.1.jar:3.9.1]
    at org.mule.module.launcher.MuleContainer.start(MuleContainer.java:172) ~[mule-module-launcher-3.9.1.jar:3.9.1]
    at org.mule.tooling.server.application.ApplicationDeployer.main(ApplicationDeployer.java:15) ~[tooling-support-3.9.1.jar:?]
    Caused by: java.lang.NoClassDefFoundError: org/mule/module/soapkit/metadata/api/FaultMetaDataResolver

    here is my wsdl file

    WSDL File for HelloService

    and my implementation is as below

    Please help me to resolve this issue

Add Comment