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
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
Add transform and consume activity in mule flow
Let’s configure Consume activity
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
%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
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
Sample project zip – call-soap-api
In a SOAP api that need to be acessed by username and password, where should be configured that ?
Add the client id enforcement policy in API manager configured as basic auth.