Back to Contents


Writing a Web Services Function

Writing Web Services in BDL is very easy with the Genero Web Services Extension package. You need only to create a classic BDL function, and to publish it as a Web Function (Web Services operation) using methods from the classes available in the com library. However, there are restrictions on the BDL function - neither input nor output parameters are allowed.

See also Tutorial: Writing a Server


Defining the Input Message

Input parameters in Genero Web Service operations are not allowed, but each Web Function can have one global variable or module variable that defines the input message of the function. This message must be a record in which each field represents one of the input parameters of the Web Function.

The name of each field corresponds to the name used in the SOAP request. These fields are filled with the contents of the SOAP request by the Web Services engine just before executing the corresponding BDL function.

Example:

DEFINE add_in RECORD 
        a INTEGER,
        b INTEGER 
        END RECORD

Note:  Genero version 2.0 allows you to add optional attributes to the definition of data types. You can use attributes to map the BDL data types in a Genero application to their corresponding XML data types. See Attributes to Customize XML Mapping for additional information.


Defining the Output Message

Output parameters in Genero Web Functions are not allowed, but each Web Function can have one global variable or module variable that defines the output message of  the function. This message must be a record where each field represents one of the output parameters of the Web Function.

The name of each field corresponds to the name used in the SOAP request. These fields are retrieved from the Web Services engine immediately after executing the BDL function,  and sent back to the client.

Example:

DEFINE add_out RECORD
          r INTEGER
          END RECORD

Note:  GWS 2.0 allows you to add optional attributes to the definition of data types. You can use attributes to map the BDL data types in a Genero application to their corresponding XML data types. See Attributes to Customize XML Mapping for additional information.


Writing your BDL Function

A Web Function is a normal BDL function that uses the input and output records that you have defined.

Example:

FUNCTION add()
  LET add_out.r = add_in.a + add_in.b
END FUNCTION

Creating and publishing the Web Services operation

Methods are available in the Genero Web Services Extension library (com) to:

The com library must be imported into each module of a Web Services Server application.

The following abbreviated example is from the Web Services Server tutorial:

IMPORT com
...
FUNCTION createservice()
  DEFINE serv  com.WebService    # A WebService
  DEFINE op    com.WebOperation  # Operation of a WebService
  --#Create WebService object
  LET serv = com.WebService.CreateWebService("MyCalculator",
                        "http://tempuri.org/webservices")
  --Create WebOperation object
  LET op = com.WebOperation.CreateRPCStyle("add", "Add", add_in, add_out)
  --Publish the operation, associating it with the WebService object
  CALL serv.publishOperation(op,NULL)
...
END FUNCTION

See the Web Services Server tutorial and Choosing a Web Service Style for complete examples and explanations.