How to Write a RemObjects SDK Server (Delphi Version)

From RemObjects Wiki

Jump to:navigation, search
Delphi Platform Header-48.png

This is a RemObjects SDK for Delphi Articles topic
Feel free to add your notes to this topic below.



This article shows how to create your first server using the RemObjects SDK (Delphi edition). Having read this article, you will probably want to continue with its companion: How to Write a RemObjects SDK Client (Delphi Version).


Note: if you are also interested in the .NET version of these articles, see How to Write a RemObjects SDK Server (.NET Version) and How to Write a RemObjects SDK Client (.NET Version).


You may use this article as a tutorial and so all steps you need to take are presented as bullet points. The source code for the completed project is attached to this article - see the link at the bottom.



Contents

Selecting the server type

The first step is to select the server type you want to create.

This is what you will be presented with (may differ, of course, depending on your Delphi and Windows version):

RO05 01.PNG

In this example we will create a simple "VCL Standalone" Executable Server. This is the simplest type of server that you can create and it does not require any web server or additional configuration to run.


Selecting the project options

The following dialog will allow you to enter basic options such as the name of your project and the project's path.

RO05 02.PNG


Notes:

  • 1) New Server Wizard checkbox: this dialog can also be displayed when running templates using our Data Abstract product. At that time, the second checkbox is checked and enabled, providing control over the Data Abstract Server Wizard. When run directly from the RemObjects SDK, the checkbox is always disabled.
  • 2) Advanced Project Options: allows fine tuning of the generated code. The most usual items you may wish to change are Service Library Name (default = NewLibrary) and Server Class (NewService). If your service is being called by non-RO clients, you will also want to change Message Class to use SOAP, XML-RPC or PostMessage (the default is our efficient BinMessage).


For the purposes of this tutorial, we will keep it simple and accept the defaults for Advanced Project Options.

Normally, you will want this option checked to create a client application too, but you will need to know how to do these simple steps yourself for creating additional clients. Accordingly, we show this separately in the How to Write a RemObjects SDK Client (Delphi Version) article.



Activate your server

Your project is now created and the main form is displayed inside the Delphi IDE. On top of the form you will see two components which correspond to the Server Class and Message Class that we selected in the previous dialog.

RO05 03.PNG


Tip: the wizard has linked the server and message components for you by adding an entry into the ROServer component's Dispatchers collection. If you add a different message component to this form, make sure to add a Dispatcher item to ROServer to link to it:

RO05 04.PNG


For more information about the available message types, see Smart Services.



The RemObjects SDK CodeGen

Immediately after hitting F9, a dialog is presented, thus allowing you to select the facilities already provided by the service.

RO05 05.PNG


Notes:

  • 1) if you have Hydra installed, you will see an additional type available: Hydra Autoupdate Service.
  • 2) the last two options are only displayed if you have Data Abstract installed.



Once this is done, the project will contain new units (see below) and a small window will be displayed at the bottom of your screen (in Delphi 6), or CodeGen messages will appear in your Message pane (Delphi 7 onwards).

RO05 06.PNG


Behind the scenes, the RemObjects SDK preprocessor has analyzed the NewLibrary.rodl file (generated when the project was first created). The preprocessor found a definition of a service for which there was no implementation unit and then created it.

You will see that three files have been generated:

1) NewLibrary_Invk.pas: contains all the internal 'plumbing'. It is regenerated each time you compile and is used by the server only. 2) NewLibrary_Intf.pas: the service interface used by the server and clients. Again, this is auto-regenerated as needed and any changes you make would be lost. 3) NewService_Impl.pas: contains the service implementation and is where you place your code. Unlike the other two files, this file does not get regenerated. If you update the service (e.g. via the RemObjects SDK | Edit Service Library menu item, as shown later) and then compile, you will get errors related to missing method(s). Simply add their interface declarations to the class and hit Ctrl+Shift+C to add implementation stubs for you to complete.


function TNewService.Sum(const A: Integer; const B: Integer): Integer;
begin
  result := A + B;
end;

function TNewService.GetServerTime: DateTime;
begin
  result := Now;
end;


Testing the server

Now that your server is running, it's time to check if it's working.

Open Internet Explorer and type in the following URL: http://localhost:8099/BIN

You will see the following XML document displayed:

RO05 07.PNG

This is it! The server is successfully running and ready to be used by RemObjects SDK clients. The only code we had to write was for our actual services.


Note: if your browser did not display the XML document shown in the screenshot above, it is either because you did not set the property ROServer.Active to TRUE or because you typed the wrong URL.



Additional

If you open your project directory, you will see the NewLibrary.rodl file, which you will maintain via the supplied?Service Builder tool.

The RemObjects SDK Service Builder will now be launched and the NewLibrary.rodl file will be open.

RO05 08.PNG

This tool is all you need to add methods to your service and modify the NewLibrary.rodl file. The Sum and GetServer time methods are the default methods that are added to each first service of all your RO Server projects.


Tip: these methods were added in the early days of the RemObjects SDK as examples to help newcomers get started and they are still used by some of the simpler samples. You may want to change this behavior, which is very simple: in Windows Explorer, navigate to the ..\ RemObjects SDK for Delphi\Templates folder and double-click on the $svclibname.rodl file. This will invoke the Service Builder, where you will be able to delete the two methods.


You are now ready to create a client to access this service, see How to Write a RemObjects SDK Client (Delphi Version) article.


Ro-48.png

Product: RemObjects SDK
Available Editions: RemObjects SDK for .NET, Delphi and Xcode

GlossaryArchitectureArticlesFeaturesLibrarySamples

Navigation
products
hubs
special
Toolbox