Web Service Calls
MapForce enables you to use HTTP APIs and WSDL-based services as mapping functions. For more general information about supported Web services, see Web Services.
Add a call to a Web service
To add a call to a Web service, follow the broad procedures below:
1.Click the toolbar button. Alternatively, open the Insert menu and click Web Service Function. This causes the Web Service Settings dialog to appear.
2.In the Service Definition section, select the relevant service definition type. Depending on the option you select, different sets of settings will be displayed. For details, see the following topics:
3.Define the settings of the Web service call.
4.Click OK. The Web service call will appear as a component in the mapping.
Change/update Web service call settings
You can change the Web service settings in the Web Service Call Settings dialog box. To open the dialog, do one of the following:
•Double-click the Web service call's component header.
•Right-click the Web service call's component header and then click Properties.
•Click the Web service component in the mapping, and, then click Properties in the Component menu.
Example of a Web service call
The mapping shown below sends a GET request to an HTTP API to retrieve a product on the basis of its ID and outputs the product's details to a JSON file.
Parts of Web service call
The Web service call component consists of two parts: Request and Response. The Request part enables you to supply data from the mapping to the Web service. The Response part enables you to access the data returned by the Web service and map it to other formats. In our example, the data returned by the service is mapped to a JSON file.
Request
The request contains several parameters and a request body.
Parameters
Parameters pass information that is needed for the server to process the request and return an appropriate response. Parameters can be of various types (e.g., path parameters, query parameters) and can serve different purposes (e.g., to filter, sort, and search data, pass authentication details).
In our example, the ID supplied to the HTTP request has the constant value of 2, which means we want to retrieve details of the product with this ID. Besides, the request contains two header parameters: Accept and Accept-Charset. The Accept parameter has the constant value of application/json, which refers to the content type MapForce wants to receive from the server. You can set parameters in the Web Service Call Settings dialog (see Parameters).
Body
In the Web service call above, the structure of the request body is not set, because we only want to send a request, using header and template parameters. Defining the structure of the request body could make sense, for example, when you want to perform POST, PUT, and PATCH operations.
Response
The response part of the call contains a status code, headers, and a response body.
Status code
The HTTP status code is a three-digit number (e.g., 404) that is sent by the server to indicate the result of the request.
Headers
Headers provide important metadata about the response (e.g., the type of content being returned) and help MapForce understand how to process the response.
The response headers returned by the Web service are mappable if they are additional headers (the ones which do not begin with Content). The Headers node of the response structure contains two child items: Name and Value.
Body
The response body receives content returned by the server. The appearance of the response body depends on the response structure you have selected.
Data at this level is binary-encoded, therefore, interacting with it directly requires MapForce mime functions. Note that you do not typically need to interact with the Body at all if the Web service expects or returns structured data such as XML or JSON. Mapping data directly to or from the Body is only necessary when you call Web services that expect or return unstructured content.
By default, the Body item is configured to parse the result if the HTTP status code ranges from 200 to 299. This means that the mapping will return an error for status codes greater than 299. Also, an error will be returned if the response cannot be parsed or the Web service cannot be called due to connection failure or DNS resolution problems.
In some cases, you might want the mapping not to throw an error even if the HTTP status code is greater than 299. To do this, click the button next to the response Body and change the HTTP status code range. Alternatively, you can create multiple response Body items. For example, you can create one body that handles successful outcomes and another body that handles errors. For details about such a setup, see Error Handling in HTTP APIs.
More examples
For examples of mappings with Web service calls, see the following topics:
•Example: Mapping Data from an RSS Feed
•Example: Calling a SOAP Web Service
•Example: OAuth 2.0 Authorization