Calling SOAP service using WSC connector

 

Let’s see how we can Call SOAP service, For this POC we will take sample SOAP service available on internet.

https://www.crcind.com/csp/samples/SOAP.Demo.CLS?WSDL

This SOAP service provide different operations like addition, division and other sample operations

https://www.crcind.com/csp/samples/SOAP.Demo.cls

We can create Sample project for this SOAP service in SOAP application then we can see all the operations

Call SOAP service

 

We will call the same operation from MuleSoft using WSC connector

As a POC we will create an API which will accept two numbers as query parameter and provide the result in response message

 

Create a sample project and add Web Service Consumer in Mule Pallet

Call SOAP service

 

Add transform and consume activity in mule flow

Let’s configure Consume activity

Call SOAP service

 

Click on add configuration

Will add the WSDL URL and it will automatically fetch the details from SOAP WSDL. In case WSDL is not accessible through internet then we can copy the WSDL and its XSDs in resource folder of mule application and refer the same.

 

Click OK and select the operation from drop down list

 

Now click on first transformation to create request for this operation

 

Double click on Arg1 and it will auto populate Dataweave

 

Now update the null value to query parameters

Call SOAP service

 

%dw 2.0
output application/xml
ns ns0 http://tempuri.org
---
{
    ns0#AddInteger: {
        ns0#Arg1: attributes.queryParams.num1,
        ns0#Arg2: attributes.queryParams.num2
    }
}

This will update the payload to XML request

Please note here we are adding the namespace while creating the XML request. This is very important as XML request will not work in case proper namespaces are not configured.

 

Also, we don’t have to create whole SOAP envelop as WSC connector will only expect SOAP body content in Payload

Call SOAP service

 

Now create a response transformation to set the proper result

%dw 2.0
output application/json
ns ns0 http://tempuri.org
---
{
result: payload.body.ns0#AddIntegerResponse.ns0#AddIntegerResult
}

Here also we can ignore SOAP Envelop and Body and as the SOAP response body will be assigned to mule event

Now run the mule application and test the service

Call SOAP service

Sample project zip – call-soap-api

  
Thank you for taking out time to read the above post. Hope you found it useful. In case of any questions, feel free to comment below. Also, if you are keen on knowing about a specific topic, happy to explore your recommendations as well.
 
For any latest updates or posts on our website, you can follow us on LinkedIn. Look forward to connecting with you there.


Share this:
Subscribe
Notify of
guest
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Daniel
Daniel
6 months ago

In a SOAP api that need to be acessed by username and password, where should be configured that ?