Step 3: Create service, start server and process requests

Code to start the Genero Web Services (GWS) Server.

Create your own MAIN module that calls the function from the generated .4gl file to create the service, then starts the Genero Web Services Server and manages requests as in MyCalculator server source.
# example2main.4gl file         -- contains the MAIN program block

IMPORT com
IMPORT FGL example1Service      -- import the generated service file

MAIN
   DEFINE create_status INTEGER
   DEFER INTERRUPT

   -- call the function generated in example1Service.4gl
   CALL example1Service.Createexample1Service()                                    
      RETURNING create_status
   IF create_status <> 0 THEN
      DISPLAY "error"
   ELSE
      # Start the server and manage requests
      CALL ManageService()
   END IF

END MAIN

FUNCTION ManageService()
   DEFINE ret INTEGER
   CALL com.WebServiceEngine.start()
   WHILE TRUE
   # Process each incoming request (infinite loop)
   ...
END FUNCTION

Copy the WHILE loop for running the service from MyCalculator server source.

The program must declare DEFER INTERRUPT. Without that declaration, an interrupt stops the program inside the waiting method, so neither the -4 status nor the int_flag test is reached.

Backward compatibility for globals

If you have generated stub files for compatibility with your GWS client app, you have a reference in the GLOBALS statement at the top of the .4gl module that links the stub file.
# example2main.4gl file            -- contains the MAIN program block

IMPORT com

GLOBALS "example1Service.inc"      -- use the generated globals file

MAIN
   DEFINE create_status INTEGER
   DEFER INTERRUPT

   CALL Createexample1Service()    -- call the function generated in example1Service.4gl 

# continue as in the example above
# ...