Using the Client Dataset in an N-Tiered Application - Application Server
(Page 2 of 4 )
The application server resides in the middle tier and acts as an intermediary between the client application and the database server. In some ways the application server plays the same role that the dataset provider plays while acting as an intermediary between the client dataset and the database server.
Creating an application server in Delphi is a bit different from creating other applications. If you intend to create a web service using SOAP as the transport protocol, choose Web Server as the the type of application in the SOAP Server application category of the new item dialog box. If you are using any other protocol like DCOM or TCP/IP, simply select new application from the File menu or New Items dialog box.
What makes the application server different from other applications is the remote data module which acts as the broker for the application server. You can add the TRemoteDataModulecomponent to your application from the Multitier category of the New Items dialog box. This module acts as the repository of all objects in an application server and implements the IAppServer interface that the client application uses to connect to the server. When you create a new RemoteDataModule, you are required to specify a class name which acts as the base name of the interface of that class. You can also specify the kind of threading model you want to implement and the number of instances you wish to allow.
If you are creating a Web Service you can add TSoapDataModulefrom the Web Services page of the New Items dialog box. It implements an invokable interface, the IAppServerSOAPinterface, to communicate information in a SOAP-based multi-tiered database application. As with TRemoteDataModule, TSoapDataModule alsorequires a class name during creation which acts as the base name of the interface for that class. There are more ways to create an application server but I will not go into the details. Instead, I will proceed to demonstrate how a remote data module and dataset provider can be utilized in the application server.
After adding a remote data module according to your requirements, drop database components that interact with the database server on the data module. For instance, to connect to a Microsoft SQL Server using ADO, drop a TADOTable component, specify the connection parameters in its ConnectionStringproperty and the table you want to access in the TableName property. Next add a dataset provider component and assign the TADOTable component's name to the dataset property of the dataset provider. This will ensure that when the client dataset connects to it and requests data, it will fetch the required records from the connected TADOTable instance. Add a dataset provider component for every dataset that you want to access from the client. If you are using XML documents for storing data, add a XMLProvider component for every XML document.
You can use the event handlers of the module to write code to ensure that the transactions and operations conform to the business rules. They can also be used to implement custom methods and influence the data packets that are being sent to the server for update. This feature is discussed in the follow-up article.
An application server does not initiate connection with the client; it waits for the client to initiate a connection. So after creating the application it would be necessary to make sure that it is found by the client application. Executing it once to get it registered as an application server, the client application can then find it and receive the IAppServer interface through which it interacts with the application server. You can also register it by passing the “/regserver” parameterin the command line or using the parameter option in the IDE. To unregister it, simply pass the “/unregserver” parameter.
Next: Client Application >>
More Delphi-Kylix Articles
More By Danish Ahmed