XData as windows service

Hi!

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);
begin
  ServerContainer := TServerContainer.Create(nil);
  ServerContainer.SparkleHttpSysDispatcher.Start;
  Started := true;
end;

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).

Regards,

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.

2 Likes

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.