{ DreamFactory: 'Blog' }

REST enable your SOAP services with DreamFactory

Posted by Todd Appleton

Wed, Mar 2, 2016

DreamFactory allows you to REST enable databases, file storage, remote web services, and more. Now you can also access XML based SOAP services using the DreamFactory REST API. Request and response payloads between your app and DreamFactory are in JSON format. DreamFactory takes care of converting the JSON request to a SOAP request and the SOAP response to a JSON response. We auto-generate a Swagger service definition from the service's WSDL so you can use the API Docs tab in the admin console to test your service, then use the generated URLs to call the service from your own app.

In this blog post I'll show you how to configure DreamFactory to connect to a simple SOAP service for fahrenheit/celsius temperature conversion. Before we get started, have a look at the WSDL for this simple service. Ummm yeah, this is what we'd like to avoid. Here we go. No XML, no fuss.

Create a new SOAP service

  • Go to the Services tab in the admin console for your DreamFactory instance.
  • Click Create and set Service Type to ‘SOAP Service’.
  • Set the name to ‘temp’. This will be part of the URL when you call the service.
  • Set the label to ‘Temperature’.
  • Click the Config tab and enter the WSDL URI for the SOAP service. Set it to 'http://www.w3schools.com/xml/tempconvert.asmx?WSDL'.
  • Click Create Service to save your new service.
soap_1.png soap_2.png

Explore the service in API Docs

Click on the API Docs tab in the admin console, and select the 'temp' service from the list. It'll expand to show the available operations.

soap_3.png

This UI was auto-generated based on the information obtained from the WSDL you specified when creating the service.

Click the blue GET button next to /temp then scroll down and click the Try it out! button. You'll see the request URL and response.

GET http://localhost:8888/api/v2/temp
{
  "resource": [
    {
      "name": "CelsiusToFahrenheit"
    },
    {
      "name": "FahrenheitToCelsius"
    }
  ]
}

It also shows the cURL command for the request. The URL ends with 'temp' which is the service name. Since we did a GET on the service name, the response indicates the available operations for the service, CelsiusToFahrenheit and FahrenheitToCelsius. Again, all of this information was discovered from the WSDL when the service was created.

To call one of these functions, click the green POST button next to /temp/CelsiusToFahrenheit.

soap_4-1.png

Click Model Schema in the lower right, then click in the yellow text area to auto-populate the body text area. Change the value in the request body from "string" to a celsius temperature to convert. This is the JSON payload for your request. Click Try it out! and you'll see the request URL, this time with the operation name CelsiusToFahrenheit appended to the service name.

POST http://localhost:8888/api/v2/temp/CelsiusToFahrenheit

{
  "Celsius": "100"
}

The response contains the converted temperature. It's a single value in this case, but of course the JSON can be more complex depending on your SOAP service.

{
  "CelsiusToFahrenheitResult": "212"
}

Since it's JSON, the result can be accessed as response.CelsiusToFahrenheitResult. For the other operation FahrenheitToCelsius, the request looks like this.

POST http://localhost:8888/api/v2/temp/FahrenheitToCelsius

{
  "Fahrenheit": "32"
}

And the response is

{
  "FahrenheitToCelsiusResult": "0"
}

Your app can make the same calls as the API Docs. Just use the request URLs in the API docs as examples. The beauty of all this is that you can access your SOAP services easily using REST and JSON, and also use roles to limit what apps and users have access to those services. Try using DreamFactory to access your own SOAP services and let us know what you think.

Get started with DreamFactory with a free hosted DreamFactory development environment. Or, download and run it on the server, cloud, or desktop of your choice.

DreamFactory Silver XML JSON SOAP

Weekly Digest

Recent Posts