Best way to communicate between Windows Service and GUI?

  • Thread starter Thread starter Adam Clauss
  • Start date Start date
A

Adam Clauss

I am currently developing an application which will primarily run as a service that starts with Windows. However, I want to also
have an 'administration' tool that can be run that controls various aspects of the service (not simply start/stop). What methods
exist to communicate between these two separate processes? And pros/cons of them?

Thanks!
 
One of the most straightforward methods that I can think of would be to use
remoting. Remoting lets you appear to instance an object in your client
code that is really running in the server process (kind of like DCOM).

A pro would be that you would actually be able to install the admin tool on
separate workstations if you wanted to. One con that I can think of off the
top of my head: using the built-in remoting channels, the server would be
required to have TCP/IP, even if both the service and the admin tool were
running on the same box -- that's because the remoting channels that come
with the framework route their messages through TCP/IP.


Adam Clauss said:
I am currently developing an application which will primarily run as a
service that starts with Windows. However, I want to also
have an 'administration' tool that can be run that controls various
aspects of the service (not simply start/stop). What methods
 
Adam,
In addition to Remoting you can use ServiceBase.OnCustomCommand to send
simply Integer commands to your Service. Allowed values are 128 to 256.

You would use ServiceController.ExecuteCommand to execute the individual
commands.

Of course anything with any substance I would use .NET Remoting as J.Marsch
suggested.

In the Service Manager/Administrator that I am working on I currently intend
on use Custom Commands where I pass an Enum, as all the commands will be
super simple...

Hope this helps
Jay

Adam Clauss said:
I am currently developing an application which will primarily run as a
service that starts with Windows. However, I want to also
have an 'administration' tool that can be run that controls various
aspects of the service (not simply start/stop). What methods
 
Thanks to both of you for your suggestions. My commands I will be issuing will be more complex than simple integers, so I will look
into the Remoting method.
 
Another option is to expose object instances through System.Management and
WMI in your service, the client application(s) can query these instances. To
pass commands to the service you could install a Management event handler
and let the client fire events passing objects as command arguments.
The advantage over remoting is that it uses DCOM as wire level protocol with
it's built-in security.

Willy.
 
Back
Top