RAD Studio
ContentsIndex
PreviousUpNext
Calling Server Interfaces

Applications do not need to call the IAppServer or IAppServerSOAP interface directly because the appropriate calls are made automatically when you use the properties and methods of the client dataset. However, while it is not necessary to work directly with the IAppServer or IAppServerSOAP interface, you may have added your own extensions to the remote data module's interface. When you extend the application server's interface, you need a way to call those extensions using the connection created by your connection component. Unless you are using SOAP, you can do this using the AppServer property of the connection component. 

AppServer is a Variant that represents the application server's interface. If you are not using SOAP, you can call an interface method using AppServer by writing a statement such as  

MyConnection.AppServer.SpecialMethod(x,y);

However, this technique provides late (dynamic) binding of the interface call. That is, the SpecialMethod procedure call is not bound until runtime when the call is executed. Late binding is very flexible, but by using it you lose many benefits such as code insight and type checking. In addition, late binding is slower than early binding, because the compiler generates additional calls to the server to set up interface calls before they are invoked.

When you are using DCOM as a communications protocol, you can use early binding of AppServer calls. Use the as operator to cast the AppServer variable to the IAppServer descendant you created when you created the remote data module. For example:

with MyConnection.AppServer as IMyAppServer do
SpecialMethod(x,y);

To use early binding under DCOM, the server's type library must be registered on the client machine. You can use TRegsvr.exe, which ships with Delphi to register the type library.

Note: See the TRegSvr demo (which provides the source for TRegsvr.exe) for an example of how to register the type library programmatically.

When you are using TCP/IP or HTTP, you can't use true early binding, but because the remote data module uses a dual interface, you can use the application server's dispinterface to improve performance over simple late binding. The dispinterface has the same name as the remote data module's interface, with the string 'Disp' appended. You can assign the AppServer property to a variable of this type to obtain the dispinterface. Thus:

var
TempInterface: IMyAppServerDisp;
begin
  TempInterface :=IMyAppServerDisp(IDispatch(MyConnection.AppServer));
...
TempInterface.SpecialMethod(x,y);
...
end;

Note: To use the dispinterface, you must add the _TLB unit that is generated when you save the type library to the uses clause of your client module.

If you are using SOAP, you can't use the AppServer property. Instead, you must obtain the server's interface by calling the GetSOAPServer method. Before you call GetSOAPServer, however, you must take the following steps:

  • Your client application must include the definition of the application server's interface and register it with the invocation registry. You can add the definition of this interface to your client application by referencing a WSDL document that describes the interface you want to call. For information on importing a WSDL document that describes the server interface, see Importing WSDL documents. When you import the interface definition, the WSDL importer automatically adds code to register it with the invocation registry. For more information about interfaces and the invocation registry, see Understanding invokable interfaces.
  • The TSOAPConnection component must have its UseSOAPAdapter property set to True. This means that the server must support the IAppServerSOAP interface. If the application server is built using Delphi 6 or Kylix 1, it does not support IAppServerSOAP and you must use a separate THTTPRio component instead. For details on how to call an interface using a THTTPRio component, see Calling invokable interfaces.
  • You must set the SOAPServerIID property of the SOAP connection component to the GUID of the server interface. You must set this property before your application connects to the server, because it tells the TSOAPConnection component what interface to fetch from the server.
Assuming the previous three conditions are met, you can fetch the server interface as follows:

with MyConnection.GetSOAPServer as IMyAppServer do
SpecialMethod(x,y);

 

IDispatch* disp = (IDispatch*)(MyConnection->AppServer)
IMyAppServerDisp TempInterface( (IMyAppServer*)disp);
TempInterface.SpecialMethod(x,y);
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!