Call a RPC-style SOAP Web Service in Mule 4

Overview

If you’ve worked with the Web Service Consumer connector, you’ve probably run into this error message at one point when given a SOAP endpoint.


RPC style WSDLs are not supported by the Web Service Consumer

But don’t worry, there are workarounds to accomplish integrating with these endpoints. In this article, I’ll show you how you can still leverage Anypoint Studio to call this web service; it just requires an additional step. Before diving into this, check out this post. It does a great job covering the different types of WSDLs.

Pre-Requisites

  • Anypoint Studio 7.4.2
  • Mule EE 4.2.2
  • Web Service Consumer 1.5.7
  • SOAP UI

Generate SOAP Request

The Web Service Consumer is unable to parse a RPC-style WSDL to extract the operations that are available through the SOAP web service so you need to get or generate the SOAP XML requests outside of Studio. The easiest way to do this is to leverage a tool like SOAP UI. Once you have a copy installed, here is the process to extract the SOAP XML request.

  1. Open SOAP UI
  2. Click on New SOAP Project
  3. Give the project a name (e.g. Weather) and copy and paste the URL for the SOAP WSDL endpoint that you’re trying to call. For this example, I’m going to use the National Weather Service WSDL – https://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php?wsdl

  4. Click OK
  5. SOAP UI will extract the operations that are available. Select the one that you plan to call in Anypoint Studio. For this example, I’m using the LatLonListZipCode operation. Copy the request XML and switch over to Anypoint Studio.

Build Flow in Anypoint Studio

  1. In your project, right click on the src/main/resources folder and click on New > File

  2. Give the file a name and click on Finish
  3. Paste the XML request and save the file.

  4. For this example, I’m going to build a simple flow to pass the SOAP request to an HTTP Request operation. It should look like this.

  5. Let’s walk through each component. We’ll start with the HTTP Request first.

HTTP Request

  1. In the HTTP Request config, click on the green plus sign.
  2. Change the protocol to match the SOAP endpoint (e.g. HTTPS). Fill in the Host with the hostname and the Port according to the Protocol. Click on OK.

  3. In the Request section, change the Method dropdown to POST and fill in the Path field with the remaining path to call the SOAP endpoint

  4. Click on the Headers tab and add two variables
    1. Content-Type – “text/xml; charset=utf-8”
    2. SOAPAction – “https://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl#LatLonListZipCode”


Transform Message (Before HTTP Request)

  1. In the Transform Message component before the HTTP Request, right click on the Object and click on Set Metadata
  2. Click on Add
  3. Enter a name for the Type ID (e.g. rpc) and click on Create type
  1. Change the Type dropdown to XML, change the XML metadata source to Example and browse and select the XML that we generated in SOAP UI. For the Root Element Name, change the value to {http://schemas.xmlsoap.org/soap/envelope/Envelope}. Once the metadata is generated from the file, click on Select
  1. Back in the transform message, expand the metadata for the output and double click on zipCodeList. The DataWeave script will be generated with the correct namespaces. Change the null value to a zip code string (e.g. “60621”)

Transform Message (After HTTP Request)

  1. For the sake of simplicity, I’m just going to output the response from the SOAP endpoint as XML. When you open the Transform Message component, just change the DataWeave script to look like the following.
%dw 2.0
output application/xml
---
payload

Run Example

  1. Right-click and select Run project <project name>
  2. Switch to a browser and open the URL that will call the flow. If everything was configured correctly, you’ll see the following response back from the SOAP endpoint.

Summary

While the Web Service Consumer doesn’t support RPC style WSDLs, you can still configure a flow to call the endpoint in Mule. There is an extra step of generating the SOAP XML requests using a tool like SOAP UI but you still get the DataSense benefits in DataWeave when you set up the metadata for the output.

For the Transform Message component after the HTTP Request, you can also configure the input metadata if you want to parse and extract data from the response. You’ll just need to grab the expected XML response from SOAP UI.

Hopefully this helps you. If you have any questions, feel free to leave a comment below or email me.


Posted

in

by

Tags:

Comments