Convert a Data Abstract Code-First Server to an ISAPI Module

 

Ok, so you have your RemObjects Data Abstract server perfected and it is running great. However, you now want to convert it to an ISAPI module to deploy to your Windows Server running IIS. The RemObjects wizards don’t have an option to help you with this, so what do you do?

 

Well the first thing you want to do is to add a Remoting SDK ISAPI/NSAPI Server project to your server’s project group. This is simply a matter of right-clicking on the project group in RAD Studio’s Project manager window and selecting “Add New project…

 

Next you will need to open the ISAPI projects main source file and remove the following lines as they are not needed in your code-first server:

{#ROGEN:NewLibrary.rodl} // RemObjects: Careful, do not remove!

and

{$R RODLFile.RES} // RemObjects: Careful, do not remove!

 

After you have created the base Remoting SDK ISAPI/NSAPI server project and removed the two lines above, you need to add all of the files (except the project source and any form files) from your standalone server project to your new DLL project.

The next step is to modify the ISAPI project’s main source file’s main code block to be the same as the following code:

begin
  CoInitFlags := COINIT_MULTITHREADED;
  Application.Initialize;
  ServerDataModule := TServerDataModule.Create(nil);
  Application.CreateForm(TWebModule1, WebModule1);
  Application.Run;
end.

 

Now you need to open your projects main data module and modify its OnCreate handler as follows (making sure to define the ISAPI_SERVER directive in the ISAPI project’s options:

procedure TServerDataModule.ModuleCreate(Sender: TObject);
begin
  {$IF NOT Defined(ISAPI_SERVER)}
  Server.Active := true;
  {$ENDIF}

  ServerDataModule := Self;
end;

 

NOTE: If you are using AES Encryption (and I highly recommend you do so) you should copy the TROAESEncryptionEnvelope component from your data module to your web module. From there you can create a Envelope entry in your message component that points to the new AES encryption envelope. Then make sure it is enabled.

 

The next step you need to perform is to add an OnCreate handler for login service class that contains the following code:

procedure TLoginService.SimpleLoginServiceCreate(Sender: TObject); 
begin 
  Self.SessionManager := ServerDataModule.SessionManager; 
end;

 

Also your data service class needs to have an OnCreate handler like the following:

procedure TDataService.DataAbstractServiceCreate(Sender: TObject);
begin
  Self.SessionManager := ServerDataModule.SessionManager;

  Schema.ConnectionManager := ServerDataModule.ConnectionManager;
  Schema.DataDictionary := ServerDataModule.DataDictionary;
end;

 

NOTE: If you are using an event repository component in your data module you will need to add the following to your OnCreate handlers for your service classes:

  Self.EventRepository := ServerDataModule.EventRepository;

 

And that’s it. compile and install your new ISAPI module and you are done!