XML Schemas in Web Services

An XML schema describes the structure of an XML document. A valid XML document must be formed and must be validated. A schema defines data types, which can be either simple or complex.

An XML schema defines:
  • What elements can appear in the document
  • What attributes can appear in the document
  • What elements are child elements, sequence in which they appear, and the number of child elements
  • Whether an element can be empty
  • Default values for attributes

Input and Output Schemas

Every business process that can be run by a Web services provider can be associated with an output and/or an input schema:
  • The input schema is a schema object (XSD) that defines the structure of the XML elements present in the body of the incoming SOAP request. This element in the SOAP body is inserted “as is” into the process data of the business process to be run.

    The input schema is also used in the WSDL generated for the Web service hosting the business process, as a type definition for the input part of the operation corresponding to the business process.

  • The output schema is a schema object (XSD) that defines the structure of the XML elements to be sent as the body of the outgoing SOAP response. This element is extracted from the process data of the business process that was run by the Web service provider and inserted into the SOAP body of the response. Mapping to an output schema provides a way, if desired, to restrict what process data is passed to the consumer in the SOAP response.

    The output schema is also used as a type definition in the WSDL generated for the Web service hosting the business process, in the output part of the operation corresponding to the business process.

Sterling B2B Integrator provides default input and output schemas. The default schemas do not contain any restrictions on the structure or type of data in the message, but are included for use by the application if no other schema is provided.
  • Default input schema – Contains two parameters, process data and primary document.
  • Default output schema – Contains one parameter, process data. It passes the entire process data in the response.

The best practice is to create input and output schemas for each business process you want to use in a Web service to ensure that data is structured correctly.

The user can also select whether to validate incoming or outgoing data, each against its respective schema.

Naming Conventions for Schemas

When creating schemas, you should provide descriptive names that include information such as the business function or consumer name/type. Additionally, include the direction (input or output) if the schema will be used for only one direction.

Business Process Schema Limitations

Business process schemas have the following limitations:
  • Each business process can have only one root element mapped to it per input or output schema.
  • Valid schemas can have one or more root elements.
  • You cannot map the same root element to multiple business processes. There should always be a one-to-one mapping relationship between a business process and a root element.
  • If a schema/root element combination has already been used with a business process, you cannot use the same combination again, even with a different business process.
  • Target namespace must be present in the schema for the WSDL to generate properly.
Note: You must add an XML schema to Sterling B2B Integrator before you can map it to an existing business process.

Web Services Schema Limitations and Structure

XML schemas for Web services have the following constraints:
  • The schemas must contain a targetNamespace.
  • The schemas must contain only one root element.

The basic Web services structure must include the following:

Node

Description

Type of data

(Required) Accepts String and other types. Default is String.

Document encoding type

(Required) Accepts UTF8 and UTF16 (SOAP specification). Default is UTF8.

WSDL Example

If you check in an output schema and select the use of the output schema during Web service creation, the elements of the schema are inserted into the “types” section of the WSDL. The following example shows the types section of a WSDL with schema elements inserted:

...
<wsdl:definitions ...
<wsdl:types> ...
<xs:schema ...
…
<xs:complexType name="CustomElement">
	<xs:sequence>
		<xs:element name="ele1" type="xsd:string"/>
		<xs:element name="ele2" type="xsd:string"/>
		<xs:element name="ele3" type="xsd:string"/>
	</xs:sequence>
</xs:complexType>
<xs:element name="outputData" type="tns: CustomElement" />
...

The type is then inserted into the definition of the output message of the corresponding operation. This is done in a new message that corresponds to the business process. The syntax for the unique name of the message element consists of the name of the business process concatenated with the word “Response”:

business_process_nameResponse

The following example shows the syntax:

...
<wsdl:message name="BP1Response">
	<wsdl:part element="mesa: CustomElement" name="outputData" />
</wsdl:message>
...
<wsdl:portType name="GISPortType">
	<wsdl:operation name="executeBP1">
		<wsdl:input message="mesa:BP1" />
		<wsdl:output message="mesa: BP1Response" />
	</wsdl:operation>
</wsdl:portType>