XData as windows service


I try to write and XData server as a windows service, but after installing it, the service runs and stops immediately.

I found some info on the web, but I'm stuck on how to properly start the service I have written this

procedure TTitaniaAdminServer.ServiceStart(Sender: TService; var Started: Boolean);
  ServerContainer := TServerContainer.Create(nil);
  Started := true;

On the documentation is written to start a new thread, but I don't know how to do it with XData with a datamodule: http://docwiki.embarcadero.com/Libraries/Sydney/en/Vcl.SvcMgr.TService.OnExecute

Is there any extra examples about this topic? If not, could you provide me a basic code to understand the problem?

Hi Gomezel,

Do you get any exceptions? Have no idea what may be wrong, but you certainly do not need to create any thread.

It should be as simple as create a new Windows Service Application from Delphi template, and on ServiceStart create your XData server DataModule and activate the dispatcher (as it looks you're already doing).


1 Like

you are probably using httpsys from the source.
One common problem when starting server is that the port/url namespace must be reserved once before.
You can use the Thttpsysserverconfig from an administrator account.


Also, don't forget that when running as a service, the application runs under a different user, so permissions are different. Also the current directory is different. Make sure you are not doing any operations that might be forbidden for other users, like accessing user-specific folders, things like that.

I am new to XData and am struggling with getting a service running as as Windows Service. I am currently getting the same message reported above by Gomezel - service runs and stops immediately. I have tried suggestions above with no luck.

I am probably missing something basic. What basic steps do I need to take to get a simple service going? Is there an example app available?