Archived

This forum has been archived. Please start a new discussion on GitHub.

Windows Service suggestions

Hello all,
I am working on an Ice C# windows service(ServiceBase). I want to make sure I am opening and closing connections, freeing up resources, etc properly.
I approached it like this:

In service class, onStart method I invoke run method of my Ice.Application class.
Within the run method I create a communicator, then object adapter, and then activate the adapter.

The service seems to work fine, although I am not 100% sure I have done all that is needed.

Can anyone talk me through the reccomended or correct way to provide Ice service functionality through a Windows service?

Thanks a million!,
Powell

Comments

  • Hello all,
    Within the run method I create a communicator, then object adapter, and then activate the adapter.

    The service seems to work fine, although I am not 100% sure I have done all that is needed.

    When you derive from ServiceBase, you normally initialize the Ice run time in the OnStart() method, and tear it down again in the OnStop() method.

    You can do the same for OnPause() and OnContinue(). Alternatively you can put the adapters into the holding state in response to onPause() and back into the active state in OnContinue(). The up-side of doing this is that it is transparent to clients (at least up to a point) because a paused service looks like a slow service to clients. On the down-side, it can cause clients to get suspended if they keep sending requests because the TCP/IP flow control can cause the client-side transport buffers to fill up. (Depending on timeout settings, clients may also experience timeouts.) However, in general, putting all adapters into the holding state is probably the most appropriate thing to do.

    Cheers,

    Michi.
  • I am using C# and SSL for my service.
    I have a console app that has all the same functionality that works like a charm.
    My service works fine when I use a simple tcp setup, but when I try the service with an SSL setup, I have problems.
    I think I am having difficulty figuring out how to point my service code to my config file.
    In a console app, it is easy to point to a config, like so:
    public static void Main(string[] args)
    {
    server app = new server();
    int status = app.main(args, @config.server);
    ....

    I am having trouble determining where to do this in a windows service(ServiceBase).
    Any advice greatly appreciated.

    Thanks,
    Powell
  • mes
    mes California
    Hi,

    A Windows service generally uses the system directory as its default working directory, so you have to be careful when specifying a relative pathname. I recommend using an absolute pathname instead, such as C:\MyService\config.server. You also must make sure that the service has sufficient privilege to access the configuration file. I discussed these issues in a newsletter article.

    Take care,
    - Mark
  • I have used fully qualified paths, but still no luck.
    My question is to how or where the config file is specified in a windows service.

    Thanks,
    Powell
  • mes
    mes California
    My question is to how or where the config file is specified in a windows service.
    The easiest way is to include it as part of the service's command-line options, such as

    myservice --Ice.Config=C:\MyService\config.server

    In C++, the Ice::Service class allows you to install a service and include whatever command-line arguments are necessary. You would probably have to implement support for this yourself in C#.

    Your service can also determine the location of the configuration file at run time and then define Ice.Config or load the properties manually.

    Take care,
    - Mark