Elements of a Service Description
A Service Description is represented as an XML document that follows an XML schema. This single XML document contains all the information for a single Service Description: name, description, input and output parameters, and input and output mapping. For a full listing of the XML schema, refer to Appendix A - Service Description Schema . The top-level element in a Service Description is the serviceDescription element. This element, and all of its children, must be in the XML namespace with a URI of http://www.ibm.com/xmlns/prod/forms/services/serviceDescription/1.0.
Each Service Description must contain a unique id that identifies it to the Forms Experience Builder server. The id can contain any characters that are valid as a component of a URL path. These characters include:
Because a Service Description ID is a surrogate for the Service Description itself, this ID does not need to be descriptive. Any UUID is a valid choice for a Service Description ID because it guarantees uniqueness and contains only characters that are valid in a URL path component.
- Alphabetical letters – [A-Z], and [a-z]
- Numerals – [0-9]
- Hyphens – [-]
- Underscore – [_]
A Service Description must reference a Service Transport to perform its underlying operation. Each Service Transport has its own unique transportId that uniquely identifies it to the Forms Experience Builder server. The ID for a Service Transport must be made available by its developer.
Name and Description
To help users build Forms Experience Builder applications using services, each Service Description contains both a name, and adescription. See Localizing Service Descriptions for additional information on how to provide names and descriptions in multiple languages.
If the Service Description is not localized in the language of a particular user, the defaultLocale contains the locale in which the name and description must be presented. For example, if a user asks for the Service Description in French, but the Service Description has only English and Spanish strings, the English is returned if en is set as the defaultLocale.
The credentials contains the configuration for a Credentials Provider. The ID of the credentials provider is specified in the providerId attribute. The credentials element can contain zero or more property elements to configure the properties of the specified Credentials Provider. Each property element must contain a name attribute whose value is the name of the property being configured, and a value attribute that contains the value of the property.
Not all Credentials Providers are applicable to all Service Transports. Therefore, the documentation for each Service Transport must be consulted before configuring the credentials element. If the configured Service Transport does not understand the provider specified by providerId, the Service Description is not available.
Every Service Description must specify its input and output structures. These structures outline the ID, name, description, and type of each parameter as well as any sub-parameters. In addition to the parameter structure, bindings might also contain a section that declares how data going into the Service Transport is mapped from the input structure and how data coming from the Service Transport is mapped to the output structure.
There are two top-level elements for bindings: inbound, and outbound. Inbound defines the binding for data coming into the Service Description from the Builder Application. Outbound defines the data going to the Forms Experience Builder application from the Service Description. Only one of each of these elements can be present within a single Service Description, and each must be placed as a child of the serviceDescription element.
Directly underneath inbound and outbound are two elements that define the main components of a binding: parameters and serviceMapping. The parameters element contains all the information related to the parameters. The contents of the serviceMapping element instructs Forms Experience Builder how to map data coming from the parameters into data for the transport and vice versa.
The parameters element contains zero or more parameter elements. Each parameter element defines a single parameter coming into or being returned from the Service Description. Each parameter element must have an id, type, name, and description. The id element uniquely identifies the parameter within the binding. The type element specifies the type of data that is expected to be contained within the parameter. The following data types are supported: STRING, BOOLEAN, DECIMAL, FLOAT, DOUBLE, INTEGER, DATETIME, TIME, DATE, and LIST.
As with the name and description child elements of the serviceDescription element, these children of parameter specify the name and description of the parameter used in Forms Experience Builder. These elements can also be localized using the xml:lang attribute.
Optionally, the mandatory element can be included for inbound bindings to specify whether the parameter must be bound before starting the Service Description. Valid values for this element are true and false, with the latter being the default.
Each parameter element can have a child element called parameters which is a container for child parameters. The contents of the parameters element is one or more parameter elements. If a parameter contains sub-parameters, its type is set to LIST. At run time, the parameter contains a list of structures with each of the sub-parameters.
The serviceMapping element contains all the information needed for the Forms Experience Builder server to map data between the Service Description parameters, and the Service Transport. Refer to Mapping Data for a Service Description for more information.
XML namespace declarations should be defined on the serviceMapping element or higher.
Sample Service Descriptions
Each example in this section includes a list of the Service Descriptions and a discussion of how each Service Description operates. The Service Descriptions in this section rely solely on the Service Transports that are shipped with the Forms Experience Builder server. Where applicable, sample and setup instructions are included.
Example 1- Simple Mapping
The following Service Description uses the HTTP Service Transport to make a request to a web server and return the content type of the response. In this example, the URL to which the request is made comes as an inbound parameter from the Builder application.
Example 2 - Augmenting Parameters with Constants
All Service Descriptions begin with a serviceDescription element, and in this example, it is defined in line 2. The serviceDescription element contains all the information needed for the Forms Experience Builder server to work with the Service Description. The unique ID of this Service Description is get-content-type as defined in line 3. The unique ID is not exposed to a user, but it must be unique. Line 5 declares the ID of the Service Transport to use, which is HTTPServiceTransport, and this is the unique ID of the HTTP Service Transport. Lines 7 and 8 define the name and description of the Service Description, which are presented to the user when designing applications.
Lines 10-20 define the inbound bindings, and lines 21-30 define the outbound bindings. As mentioned previously, the inbound bindings refer to the parameters that are flowing from the application to the Service Transport. The outbound bindings refer to the parameters that are flowing in the opposite direction.
Lines 11-19 contain all the inbound parameters, of which there is only one.
The parameter defined in lines 12-18 represents the URL to which a request is made. According to the HTTP Service Transport documentation, the parameter that contains the URL to which the request is made must be called request-url.
Line 13 defines the id of the parameter so that it matches the expectations of the HTTP Service Transport.
The name and description are defined in lines 15 and 16, and line 17 specifies that this parameter must be supplied in order for this Service Description to operate.
Lines 21-30 define the outbound parameters for the Service Description. In this case, there is only one output parameter: the content type of the response. The HTTP Service Transport dynamically creates new parameters based on the information that is returned in the HTTP response. In particular, response headers are converted to lowercase and are prefixed with response-header-. Since this Service Description is interested in the Content-Type header, the outbound parameter response-header-content-type is created in lines 23-28 to contain this data.
1: <?xml version="1.0" encoding="UTF-8"?>
6: <name xml:lang="en-us">Get Content Type</name>
7: <description xml:lang="en-us">
8: Retreives the content type of the response from an HTTP server for the configured URL.
15: <name xml:lang="en-us">URL</name>
16: <description xml:lang="en-us">URL to request.</description>
26: <name xml:lang="en-us">Content Type</name>
27: <description xml:lang="en-us">Content Type of the response.</description>
The following Service Description returns the same information as Example 1. However, in this case, we do not want the Forms Experience Builder application to supply the URL. Instead, the URL is declared using a constant, and mapped into the inbound parameters for the Service Transport.
Example 3 - Lists of Data
Like Example 1, the Service Description makes a request to an HTTP server and returns the content type of the response. However, this Service Description differs from the Example 1 because there are no input parameters to this service. The request-url HTTP Service Transport parameter is mapped into the transport via a constant.
Lines 12-17 define the constants section. There is a single constant defined in lines 13-16. This constant has an id of url-to-request specified in line 14, and a value of http://www.ibm.com, specified in line 15. The id of the constant is used when creating the parameter structure that is passed to the Service Transport. This constant is referenced in line 19 within the mapping section.
Lines 18-20 contain the mapping information. Since there is only one parameter to be sent, there is only one mapping, which is defined in line 19. This mapping specifies that the value of the Service Transport parameter named request-url is specified by the value of the constant named url-to-request.
1: <?xml version="1.0" encoding="UTF-8"?>
6: <name xml:lang="en-us">Get Content Type with Constant</name>
7: <description xml:lang="en-us">
8: Retreives the content type of the response from an HTTP server.
19: <mapping source="constant:url-to-request" sourceType="string" target="transport:request-url" targetType="string"/>
28: <name xml:lang="en-us">Content Type</name>
29: <description xml:lang="en-us">Content Type of the response.</description>
The following Service Description demonstrates the use of nested parameters. This example is the same as the Service Description used for the Countries by Region service shipped with Forms Experience Builder. This example describes how to specify a region and return a list of the names of countries within that region.
Example 4 - Mapping XML into Parameters
As with the other Service Description examples, this Service Description has its own unique ID, defined in line 3, a name, defined in lines 6-8, and a description, defined in lines 9-11. This Service Description uses the sample Countries by Region Service Transport, which is shipped with the Forms Experience Builder , and is identified by its id in line 5.
Because this Service Description has a single inbound parameter, the parameters element, in lines 13-23, of the inbound bindings in lines 12-24. parameters contains only a single parameter, which is defined in lines 14-22. The id of this parameter is region, which is what is expected by the Countries by Region Service Transport.
Since there can be multiple countries within a region, the outbound bindings, defined in lines 25-42, must contain a list parameter to contain all the information for each country. The outbound structure for this Service Description consists of a parameter called countries that contains a list of maps. Each of the maps contained within the countries list consists of a single name key that contains the name of a country. This structure is defined within the parameters element, defined in lines 26-41, of the outbound bindings section. The top-level parameter, countries, is defined between lines 27 and 40. Since the countries parameter contains other parameters, its type is set as LIST in line 29. All the parameters of the list entries are defined within the parameters element inside the countries parameter defined in lines 32-39. The single name sub-parameter is defined in lines 33-38.
Since the inbound and outbound bindings directly match what is returned by the Countries by Region Service Transport, there is no need for any mapping information. This service can be set up such that the name sub-parameter is mapped to list-like items such as drop-down options or an item in a table.
1: <?xml version="1.0" encoding="UTF-8"?>
6: <name xml:lang="en-us">
7: Countries by Region using Service Description
9: <description xml:lang="en-us">
10: Given a region, return a list of country information in that region.
17: <name xml:lang="en-us">Region</name>
18: <description xml:lang="en-us">
19: One of "Africa", "America, North", "America, South", "Asia", "Europe", or "Oceania"
30: <name xml:lang="en-us">Countries"</name>
31: <description xml:lang="en-us">List of country information</description>
36: <name xml:lang="en-us">Name</name>
37: <description xml:lang="en-us">Name of Country</description>
The following Service Description extracts data from an XML document that is returned from an HTTP request using the HTTP Service Transport.
This Service Description performs a reverse address lookup using a free Google web service. As with the other Service Description examples, the standard prologue of id, transportId, name, and description is specified in lines 3-7. This service has a single parameter, address, that can be assigned by an application, as specified in lines 10-16. Since this parameter is required in order to perform the address look-up, it is marked as mandatory in line 15.
Since this Service Description uses the HTTP Service Transport, a request-url must be specified. The URL used in this request takes the form http://maps.googleapis.com/maps/api/geocode/xml?address= [address]&sensor= [true|false]. Because there are query parameters that need to be sent, this Service Description uses the HTTP Service Transport support for query parameters by prefixing the name of the parameter with request-query-. However, because some of these query parameters are not exposed to the user, you must create a mapping section to map some constant values. The inbound binding constant section, in lines 19-32, defines the 3 constants that are used: request-url, lines 20-23, false-constant, lines 24-27, and request-method, lines 28-31. These constants contain the URL to which to request is made, a constant string value false for the sensor query parameter, and the request method. While some of these constants, including request-url and request-method, match the name of the parameter to which they are applied, there is no requirement that they match. Parameter names that match do not automatically get a constant value if it has the same name. All mapping must be explicitly defined.
In lines 33-38, the mapping section of the inbound binding maps the constants and Service Description parameters to the Service Transport parameters. Each of the mapping elements is fairly self-explanatory: the request-url constant is mapped to the request-url transport parameter; the request-method constant is mapped to the request-method transport parameter; the address parameter is mapped to the request-query-address transport parameter; and the constant false-constant is mapped to the sensor transport parameter.
The HTTP Service Transport then builds a URL out of the request-url,request-query-address, and request-query-sensor parameters, and makes a request to that URL using the HTTP method given in the request-method parameter. The response body that is returned by this request is placed in the response-entity transport parameter, which is then taken apart by the mapping section of the outbound bindings.
This service expects the response-entity to be similar to the following:
1: <?xml version="1.0" encoding="UTF-8"?>
6: <name xml:lang="en-us">Address Lookup</name>
7: <description xml:lang="en-us">Returns information related to a postal code or address.</description>
13: <name xml:lang="en-us">Address or Postal Code</name>
14: <description xml:lang="en-us"></description>
34: <mapping target="transport:request-url" source="constant:request-url"/>
35: <mapping target="transport:request-method" source="constant:request-method"/>
36: <mapping target="transport:request-query-address" source="parameter:address"/>
37: <mapping target="transport:request-query-sensor" source="constant:false-constant"/>
46: <name xml:lang="en-us">Latitude</name>
47: <description xml:lang="en-us"></description>
52: <name xml:lang="en-us">Longitude</name>
53: <description xml:lang="en-us"></description>
58: <name xml:lang="en-us">Address Information</name>
59: <description xml:lang="en-us"></description>
64: <name xml:lang="en-us">Long Name</name>
65: <description xml:lang="en-us"></description>
70: <name xml:lang="en-us">Short Name</name>
71: <description xml:lang="en-us"></description>
76: <name xml:lang="en-us">Type</name>
77: <description xml:lang="en-us"></description>
82: <name xml:lang="en-us">Type(2)</name>
83: <description xml:lang="en-us"></description>
90: <mapping source="transport:response-entity"
91: sourceRef="GeocodeResponse/result /geometry/location/lat"
94: <mapping source="transport:response-entity"
95: sourceRef="GeocodeResponse/result /geometry/location/lng"
98: <mapping source="transport:response-entity"
99: sourceRef="GeocodeResponse/result /address_component"
102: <mapping sourceRef="long_name" target="parameter:long-name"/>
103: <mapping sourceRef="short_name" target="parameter:short-name"/>
104: <mapping sourceRef="type " target="parameter:type-1"/>
105: <mapping sourceRef="type " target="parameter:type-2"/>
There is much data in this response, but only some of it is needed for this Service Description. The latitude, longitude, and a list of the address information from the first result is required. In order to get only the required information, the Service Description outlines the parameters that it expects to return in the parameters section, in lines 42-87. The Service Description then uses the mapping section, in lines 88-108, to extract the required data from the response-entity transport parameter. Each of the parameters in the parameters section is self-explanatory. Latitude and longitude are top-level parameters because there is only one of each of them in a single result. However, there are many address_component elements, each of which are returned. Therefore, the address-information parameter is a list parameter that contains sub-parameters, one for each of the pieces of information in an address_component that the Service Description wants to make available.
In lines 88-108, the service mapping section defines all the mapping that must be performed to extract the data from the XML response. Latitude, specified in lines 90-93, and longitude, specified in lines 94-97, each extract the data using a single XPath expression. The source type for each is set to XML. Mapping of a repeating structure is accomplished in a similar fashion. Lines 98-101 define the mapping for the address-information parameter. The XPath expression for address-information returns a nodeset as there are several nodes that match the expression GeocodeResponse/result/address_component. For each node that is returned, a new structure is created to contain the result of each of the sub-mappings. Each of the sub-mappings places its target into the newly created structure. Since the source of each of the sub-mappings is one of the matched nodes, the mapping elements do not specify a source. It is assumed to be the inherited context. Similarly, the reference is evaluated within the context of the source, which is inherited. After each of the sub-mappings is evaluated for a single source, the structure is added to a running list and the sub-mappings are evaluated again for the next result in the source list. When all the sources are processed, the list that was collecting the results of the map is assigned to the address-information parameter.
1: <?xml version="1.0" encoding="UTF-8"?>
6: <formatted_address>1 New Orchard Rd, Armonk, NY, USA</formatted_address>
13: <long_name>New Orchard Rd</long_name>
14: <short_name>New Orchard Rd</short_name>
30: <long_name>New York</long_name>
36: <long_name>United States</long_name>
Appendix A - Service Description Schema
The name and description elements allow you to localize an IBM Forms Experience Builder Service Description in multiple languages using duplicate elements, each with a different xml:lang attribute and contents.
The serviceMapping element of the Service Description contains all the information needed for the IBM Forms Experience Builder server to map data from the Service Description inbound data to the Service Transport
This topic contains information on how to deploy an IBM Forms Experience Builder Service Description.