Step 3: Create the service and operations
Describes how you provide your Web service and its operations to users who can access it on the net.
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 class - this is a container for web operations.
- WebOperation class - 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 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:
- Service name
- Valid namespace
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 or Document style by calling the corresponding
constructor method of the WebOperation
class. The parameters are:
- the name of the BDL function that is executed to process the XML operation
- the name you wish to assign to the XML operation
- the input record defining the input parameters of the operation (or NULL if there is none)
- the output record defining the output parameters of the operation (or NULL if there is none)
LET op = com.WebOperation.CreateRPCStyle("add", "Add", add_in, add_out)
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.
CALL serv.publishOperation(op,NULL)