Step 6: Create the server

I4GL uses Axis as server for its services, but Genero has its own server programmable via the COM library. Create a new file and add the IMPORT com instruction at beginning of the server file, then simply create the main loop in BDL that will process any incoming HTTP request.

The port of the service defined in the I4GL .4cf configuration file (via the PORTNO entry) can be reused by setting the FGLAPPSERVER environment variable to the same value before to run the server. However, only on development or for tests, on production Genero Web services requires an application server called GAS in charge of load balancing. See the GAS documentation for more details about port configuration for deployment purpose.

For example, to migrate the I4GL zipcode demo, the service must be created in the server before run the main loop as following :
MAIN
  DEFINE ret INTEGER
  DEFER INTERRUPT

  # Create zipcode_details service
  CALL create_zipcode_details_web_service()

  # Start the server on port set in FGLAPPSERVER
  #    (to be set to same value as PORTNO defined in the .4cf file)
  CALL com.WebServiceEngine.Start()

  # Handle any incoming request in a WHILE loop...
  # See <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE concept PUBLIC "-//IBM//DTD DITA IBM Concept//EN" "ibm-concept.dtd">
<concept id="c_gws_server_tutorial_009" xml:lang="en-us">
<title>Step 5: Start the GWS server and process requests</title>
<shortdesc>Once you have registered the Web Service(s), you are ready to start the Genero Web
Services (GWS) Server and process the incoming SOAP requests.</shortdesc>
<prolog></prolog>
<conbody>
<p> The GWS Server is located on the same physical machine where the application is being executed
(In other words, where <cmdname>fglrun</cmdname> executes).</p>
<p>This is the <codeph>MAIN</codeph> program block of your application.</p>
<section><title>Define a variable for status</title><p>Define a variable
to hold the returned status of the         request:<codeblock>MAIN
  DEFINE ret INTEGER</codeblock></p><p>Call the function that you created, which defined and registered the service and its
operations:<codeblock>  CALL createservice()</codeblock></p></section>
<section><title>Start the GWS Server</title><p>Use the <codeph>Start</codeph> class method of the <xref href="c_gws_ComWebServiceEngine.dita"
><codeph>WebServiceEngine</codeph></xref> class to start the
server.<codeblock>  CALL com.WebServiceEngine.Start()</codeblock></p></section>
<section id="process_request">
<title>Process the requests</title>
<p>This example uses the <codeph>ProcessServices</codeph> method of the <xref
href="c_gws_ComWebServiceEngine.dita"><codeph>WebServiceEngine</codeph></xref> class to process each
incoming request. It returns an integer representing the status. The parameter specifies the timeout
period (in seconds) for which the method should wait to process a service. The value -1 specifies an
infinite waiting
time.<codeblock>  WHILE TRUE
    # Process each incoming requests (infinite loop)
    LET ret = com.WebServiceEngine.ProcessServices(-1)
    CASE ret
      WHEN 0
        DISPLAY "Request processed."
      WHEN -1
        DISPLAY "Timeout reached."
      WHEN -2
        DISPLAY "Disconnected from application server."
        EXIT PROGRAM 
      WHEN -3
        DISPLAY "Client Connection lost."
      WHEN -4
        DISPLAY "Server interrupted with Ctrl-C."
      WHEN -10
        DISPLAY "Internal server error."
        EXIT PROGRAM
      WHEN -15
        DISPLAY "Server was not started."
        EXIT PROGRAM
      OTHERWISE
        DISPLAY "ERROR: ", STATUS, SQLCA.SQLERRM
    END CASE
    IF int_flag&lt;&gt;0 THEN
      LET int_flag=0
      EXIT WHILE
    END IF 
  END WHILE

  DISPLAY "Server stopped"

END MAIN</codeblock></p><note type="note">For testing purposes only, the GWS Server can be started in <xref
href="c_gws_server_tutorial_015.dita#c_gws_server_tutorial_015">standalone mode</xref>. In a
production environment, the Genero Application Server (GAS) is required to manage your application.
For deployment, the GWS Server application must be added to the GAS configuration. See <cite>Adding
Applications</cite> in the <cite>Genero Application Server User Guide</cite>. </note></section>
</conbody>

</concept>


END MAIN
Note: With Genero Web Services, one server can contain several services. In other words, you can put all your I4GL services into one server.