Call the stub functions

Functions in the stub file allows you to write code in your own .4gl module that calls these functions as part of your client application.

The service information obtained from the REST Web Service provides information about using the service.

Calling a stub function in the client app

In this sample client application, a call to the function myWScall updates a user resource via a call to a client stub function.

In the function the variable this is defined as a record type based on a user-defined record in the client stub, clientStub.addUserRequestBodyType. Values are passed to the variable before calling the client stub function. The variable is passed in the call to the client stub function.

Two variables are defined for the return:
  • wsstatus of type INTEGER for the error code
  • res of type STRING for details of the error that may be returned
The response from the service is checked in the CASE wsstatus statement. If the status code is not equal to zero (clientStub.C_SUCCESS), details of the error are displayed in wsstatus and res. For more information on handling errors in the response from a call to a service operation, see Handle GWS REST server errors.
IMPORT FGL clientStub

MAIN
   CALL myWScall()
END MAIN

# Function performs call to the client stub function 
FUNCTION myWScall()
    DEFINE this clientStub.addUserRequestBodyType
    DEFINE wsstatus INTEGER
    DEFINE res STRING

    LET this.user_name= "Mike Pantock"
    # ...
  
    CALL clientStub.addUser(this.*)RETURNING wsstatus, res
    CASE wsstatus
       WHEN clientStub.C_SUCCESS
         DISPLAY "Success adding new user"
       OTHERWISE
         DISPLAY "Unexpected error :", wsstatus, res
    END CASE
    
END FUNCTION

Find a client application at $FGLDIR/demo/WebServices/books.