I am using Delphi XE2 DataSnap library. My datasnap server is HTTP based (TIdHTTPWebBrokerBridge or ISAPI).
When first access the DataSnap service, the TDSServer instance will register all available server methods via TDSServerMethodProvider.Open and TDSServerMethodProvider.AddRegisterServerClasses (see unit Datasnap.DSCommonServer.pas).
The datasnap class name and server method must pre-register or else it will fail when client access the service.
I am thinking to make an application that may load the datasnap classes and server methods dynamically. My datasnap application do not know if the classes or server methods is available for access until it start looking for the service based on URL. For example, an URL like:
http:/.../datasnap/rest/TServerMethods1/ReverseString
will make the application looking for class TServerMethods1 and register before consume the method.
We may use TWebModule.BeforeDispatch event to identify the Request.URL string and determine which packages to load for corresponding datasnap classes.
By using this approach, I can write a general purpose DataSnap application that is flexible and scalable.
After examine the DataSnap source code, I found it is impossible unless some additional work to be done on existing DataSnap source. Few methods in class TDSServerMethodProvider that is crucial for registering are declare in private section: AddRegisteredServerClasses
, AddAllMethods
.
The TDSServerMethodProvider class doesn't seems to design for additional registration. It only allow to register once only.