The Structure of the Application Server
When you set up and run an application server, it does not establish any connection with client applications. Rather, client applications initiate and maintain the connection. The client application uses a connection component to connect to the application server and uses the interface of the application server to communicate with a selected provider. All of this happens automatically, without your having to write code to manage incoming requests or supply interfaces.
DataSnap is a versatile technology that provides the ability to create multi-tier client-server applications that communicate through the Internet, the local network, or the local host, using either TCP-based (TDSTCPServerTransport) or HTTP (TDSHTTPService) transport protocol. For more information regarding the DataSnap server structure, please visit Creating a DataSnap Server and Creating the Server Application.
The basis of an application server is a remote data module, which is a specialized data module that supports the IAppServer interface (for application servers that also function as a Web Service, the remote data module supports the IAppServerSOAP interface as well, and uses it in preference to IAppServer.) Client applications use the remote data module's interface to communicate with providers on the application server. When the remote data module uses IAppServerSOAP, the connection component adapts this to an IAppServer interface that client datasets can use.
There are four types of remote data modules:
- TDSServerModule: This is the remote data module for DataSnap Server. Use this type of remote data module to expose data sets, methods, SQL connections, and shared providers from the server to the client.
- TRemoteDataModule: This is a dual-interface Automation server. Use this type of remote data module if clients use DCOM, HTTP, sockets, or OLE to connect to the application server, unless you want to install the application server with COM+.
- TMTSDataModule: This is a dual-interface Automation server. Use this type of remote data module if you are creating the application server as an Active Library (.DLL) that is installed with COM+ (or MTS). You can use MTS remote data modules with DCOM, HTTP, sockets, or OLE. See Using transactional data modules for information about the benefits and limitations of using MTS or COM+ with the application server.
- TSoapDataModule: This is a data module that implements an IAppServerSOAP interface in a Web Service application. Use this type of remote data module to provide data to clients that access data from a Web Service.
Note: If the application server is to be deployed under COM+ (or MTS), the remote data module includes events for when the application server is activated or deactivated. This allows it to acquire database connections when activated and release them when deactivated.
The contents of the data module
As with any data module, you can include any nonvisual component in the remote data module. There are certain components, however, that you must include:
- A dataset component to represent the records from that database server if the remote data module is exposing information from a database server. Other components, such as a database connection component of some type, may be required to allow the dataset to interact with a database server.
- For every dataset that the remote data module exposes to clients, the remote data module must include a dataset provider. A dataset provider packages data into data packets that are sent to client datasets and applies updates received from client datasets back to a source dataset or a database server.
- An XML provider for every XML document that the remote data module exposes to clients. An XML provider acts as a dataset provider, except that it fetches data from and applies updates to an XML document rather than a database server.
Server Methods, used in DataSnap architecture, allows the developer to write methods that are part of the middle-tier. These methods are available to the client in a seamless way and can be called exactly as if the code were executing within the client binary. To use server methods you need to select the Server Methods Class option from DataSnap Server Wizard.
While executing a server method (called by a client), the server can call a callback function, which has previously been passed as argument to the server method by the DataSnap client. To see how to use callbacks, please visit the Using Callbacks page.
Note: Do not confuse database connection components, which connect datasets to a database server, with the connection components used by client applications in a multi-tiered application. You can find the connection components for multi-tiered applications in the DataSnap category or WebServices category of the Tool palette.