Search

Convert SOAP service to REST API

Overview

You want to integrate Infor OS with another system using APIs, but the system only supports SOAP web services, while Infor OS prefers REST APIs. How can you create a modern, integrated solution?


Requirements

  • Access to ION API Gateway
    • Security role: IONAPI-Administrator
    • Security role: IONAPI-User
  • API (REST vs SOAP) knowledge
  • Handlebars script knowledge for Policy Docs

Tutorial

Difficulty: Medium
Estimated completion time: 45 Minutes

SOAP Webservices are still a valid option in the API world. They are based on WSDL (Web Service Definition Language) an XML file where you can define the input and the output with the types of messages. This approach is completely different compared to the REST (REpresentational State Transfer) that is based on swagger documentation 2.0 or Open API 3.0.x.

Unless it is possible to define a SOAP web service in the API gateway, we cannot use it in ION, because the ION API connector is based on an API suite based on REST.

Register Custom API Suite

With the use of the API Policy, we can convert a SOAP web service into a REST API, and to do that we use this WSDL.

https://www.dataaccess.com/webservicesserver/numberconversion.wso?WSDL

Once we have the URL (Uniform Resource Locator) of the WSDL we can register a new custom API suite in the API Gateway.

Login to OS Portal and click on API Gateway. Click the (+) Add button.

Click on Create New button.

Input the following values and under the Target Endpoints tab, click the + button

On the Add Endpoint page, in the Target Endpoint URL field enter the WSDL URL. Enter rest in the Proxy Context field. Click Save.

https://www.dataaccess.com/webservicesserver/numberconversion.wso?WSDL

Below is the output screen after Save.

Watch the following video to view all the steps that were covered.

Upload Swagger Documentation

We need swagger documentation or an Open API 3.0.x to document our endpoint, which can be found with the following link or under the Downloads sections at the bottom the tutorial (Swagger file to import into API Gateway). This file needs to be uploaded into the API suite.

Click on the Details button for the rest Endpoint you just created.

Scroll to the bottom of the rest endpoint page and select the Documentation tab. Click the (+) button.

Download and extract the swagger.zip file from the Swagger file to import into API Gateway link in the Download section.

On the Add Documentation page, in the Name field type rest, from the drop down select Swagger in the Type field. Click the browse button on the Enter URL or Upload Swagger JSON/YAML field and select the rest.json file that was extracted from the swagger.zip file.

NOTE: Once you select the rest.json file and click open, the name in the field changes to Swagger.json.

Click Save.

Below is the output screen after Save.

Watch the following video to view all the steps that were covered.

Create Request and Response Policies

Defining the Endpoint Policy for Request and Response. We have to write the scripts that convert JSON input from REST API to XML (Request) and SOAP that converts XML to JSON as a (Response).

NOTE: You can use the following two scripts when defining the Request and Response policies in the Policy Definition section.

From JSON to XML (Request)

<jsonTransform continueOnError="false" displayName="jsonTransformMingle01"
               enabled="true" name="JSONTransformMingle01" version="1"
    xmlns="http://www.infor.com/ion/api"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://www.infor.com/ion/api jsonTransform.xsd">
    <transformations>
        <transform kind="handlebars" outputType="text/xml;charset=UTF-8"><![CDATA[<soap:Envelope
            xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
            xmlns:web="http://www.dataaccess.com/webservicesserver/"><soap:Header/><soap:Body><web:NumberToWords><web:ubiNum>{{number}}</web:ubiNum></web:NumberToWords></soap:Body></soap:Envelope>
]]>
        </transform>
    </transformations>
</jsonTransform>

From XML to JSON (Response)

<jsonTransform continueOnError="false" displayName="jsonTransformMingle01"
               enabled="true" name="JSONTransformMingle01" version="1"
    xmlns="http://www.infor.com/ion/api"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://www.infor.com/ion/api jsonTransform.xsd">
    <transformations>
        <transform kind="handlebars" outputType="application/json">
            <![CDATA[{"text": "{{jsonPathValue '$..m:NumberToWordsResponse.m:NumberToWordsResult'}}"}]]>
        </transform>
    </transformations>
</jsonTransform>

Scroll to the bottom of the rest endpoint page. Select the Endpoint Policies tab and click the (+) button under Request Policies.

From the drop down select Transformation for the Policy Type field, in the Name field type input. For the Policy Definition replace the content with the From JSON to XML request script information displayed in a previous step. Click Save.

Go back to the rest endpoint page and under the Endpoint Policies tab click the (+) button under Response Polices.

From the drop down select Transformation for the Policy Type field, in the Name field type output. For the Policy Definition replace the content with the From XML to JSON response script information displayed in a previous step. Click Save.

Below is the output screen after Save.

Watch the following video to view all the steps that were covered.

Test API

On the rest Endpoint page, select the Documentation tab and click the POST button, then click the Try it out button,

Change the number value from string to 101 and click the Execute button.

In the Response Body you should see the results, notice the one hundred and one content is displayed. This is telling you it is working.

Watch the following video to view all the steps that were covered.

Test ION API Connection Point

Go to the ION tab, expand Connect and select Connection Points. Click on the (+) Add button.

From the drop down, select API.

Watch the video below on how to create a Service Account.

In the Name field type soap2rest_cp, click the IMPORT button to import your Service Account. Select the folder button and select your ServiceAccount csv file that was generated when creating a service account..

Click Ok.

Below is the output screen after Ok.

Select the Documents tab and click the (+) button. Click on the SELECT button at the bottom of the screen.

From the drop down select soap to rest.

Select the search button and select the CustomerAPI/soap/rest API. Click Ok.

In the API Call Name field type soap.

Select the Request Body tab and click on the EXAMPLE button. You will change the string number value to 101.

Select the Output Documentation tab and select the Document search button. Search and select the AnyDocuments option, click Ok.

Click the TEST button, you will receive the Warning message, click Yes.

Click the Test button.

You will notice the Output displaying the one hundred and one message. This tells us the API call is working and the Soap to REST conversion is successful.

Watch the following video to view all the steps that were covered.

Downloads

Resources

Online help documentation: