Creating Web server applications with Web Broker

To create a new Web server application using the Web Broker architecture:

1 Select FilelNew lOther.

2 In the New Items dialog box, select the New tab and choose Web Server Application.

3 A dialog box appears, where you can select one of the Web server application types:

  • ISAPI and NSAPI: Selecting this type of application sets up your project as a DLL, with the exported methods expected by the Web server. It adds the library header to the project file and the required entries to the uses list and exports clause of the project file.
  • CGI stand-alone: Selecting this type of application sets up your project as a console application, and adds the required entries to the uses clause of the project file.
  • Apache: Selecting one of these two application types (1.x and 2.x) sets up your project as a DLL, with the exported methods expected by the applicable Apache Web server. It adds the library header to the project file and the required entries to the uses list and exports clause of the project file.
  • Web Application Debugger stand-alone executable: Selecting this type of application sets up an environment for developing and testing Web server applications. This type of application is not intended for deployment.

Choose the type of Web Server Application that communicates with the type of Web Server your application will use. This creates a new project configured to use Internet components and containing an empty Web Module.

The Web module

The Web module (TWebModule) is a descendant of TDataModule and may be used in the same way: to provide centralized control for business rules and non-visual components in the Web application.

Add any content producers that your application uses to generate response messages. These can be the built-in content producers such as TPageProducer, TDataSetPageProducer, TDataSetTableProducer, TQueryTableProducer and TInetXPageProducer, or descendants of TCustomContentProducer that you have written yourself. If your application generates response messages that include material drawn from databases, you can add data access components or special components for writing a Web server that acts as a client in a multi-tiered database application.

In addition to storing non-visual components and business rules, the Web module also acts as a dispatcher, matching incoming HTTP request messages to action items that generate the responses to those requests.

You may have a data module already that is set up with many of the non-visual components and business rules that you want to use in your Web application. You can replace the Web module with your pre-existing data module. Simply delete the automatically generated Web module and replace it with your data module. Then, add a TWebDispatcher component to your data module, so that it can dispatch request messages to action items, the way a Web module can. If you want to change the way action items are chosen to respond to incoming HTTP request messages, derive a new dispatcher component from TCustomWebDispatcher, and add that to the data module instead.

Your project can contain only one dispatcher. This can either be the Web module that is automatically generated when you create the project, or the TWebDispatcher component that you add to a data module that replaces the Web module. If a second data module containing a dispatcher is created during execution, the Web server application generates a runtime error.

Note The Web module that you set up at design time is actually a template. In ISAPI and NSAPI applications, each request message spawns a separate thread, and separate instances of the Web module and its contents are created dynamically for each thread.

Warning The Web module in a DLL-based Web server application is cached for later reuse to increase response time. The state of the dispatcher and its action list is not reinitialized between requests. Enabling or disabling action items during execution may cause unexpected results when that module is used for subsequent client requests.

The Web Application object

The project that is set up for your Web application contains a global variable named Application. Application is a descendant of TWebApplication that is appropriate to the type of application you are creating. It runs in response to HTTP request messages received by the Web server.

Warning Do not include the Forms or QForms unit in the project uses clause after the CGIApp, ApacheApp, ApacheTwoApp, or ISAPIApp unit. Forms also declares a global variable named Application, and if it appears after the CGIApp, ApacheApp, ApacheTwoApp, or ISAPIApp unit, Application will be initialized to an object of the wrong type.

Was this article helpful?

+1 0

Post a comment