Step 3: Create the service and operations

The Genero Web Services library (com) provides classes and methods that allow you to use Genero BDL to configure a Web Service and its operations.

  • WebService - this is a container for web operations.
  • WebOperation - describes the operation.

Define variables for the WebService and WebOperation objects

FUNCTION createservice()
  DEFINE serv  com.WebService    # A WebService
  DEFINE op    com.WebOperation  # Operation of a WebService

Choose a Namespace

XML uses namespaces to group the element and attribute definitions, and to avoid conflicting names. In practice, a namespace must be a unique identifier (URI: Uniform Resource Identifier). If you do not know the unique identifier to use, your company's Web site domain name is guaranteed to be unique (such as "www.mycompany.com"); then, append any string.

Examples of valid namespaces for the fictional My Company company:

  • "http://www.mycompany.com/MyServices"
  • "http://www.mycompany.com/any_string"

Another option (for testing only) is to use the temporary namespace "http://tempuri.org/".

Create the WebService object

Call the constructor method of the WebService class. The parameters are:

  1. Service name
  2. Valid namespace
This example uses the temporary namespace and creates a Service named "MyCalculator".
LET serv =
  com.WebService.CreateWebService("MyCalculator", "http://tempuri.org/webservices")

Create the WebOperation object

A WebService object can have multiple operations. The operations can be created in RPC style or Document style by calling the corresponding constructor method of the WebOperation class. The parameters are:

  1. the name of the BDL function that is executed to process the XML operation
  2. the name you wish to assign to the XML operation
  3. the input record defining the input parameters of the operation (or NULL if there is none)
  4. the output record defining the output parameters of the operation (or NULL if there is none)
To create the operation for the previously defined add function in RPC style:
LET op = com.WebOperation.CreateRPCStyle("add", "Add", add_in, add_out)
To create the operation for the previously defined add function in Document style:
LET op = com.WebOperation.CreateDOCStyle("add", "Add", add_in, add_out)

Mixing RPC style and Document style operations in the same service is not recommended, as it is not WS-I compliant. See Web Services Styles for additional information about styles.

The rest of the code in your application is the same, regardless of the Web Services style that you have chosen.

Publish the operation

Once an operation is defined, it must be associated with its corresponding WebService (the operation must be published). The publishOperation method of the WebService object has the following parameters:

  • the WebOperation to be published
  • a string to identify the operation if several operations have the same name; if this is NULL, the default value is an empty string
For example, to publish the Add operation of the Calculator service, which was defined as op:
CALL serv.publishOperation(op,NULL)