Search code examples
c#wcfwindows-servicesservicecontroller

best way to access a windows service via GUI


I'm curious about the best way for a C# gui to access the functions of a Windows Service, be it WCF or ServiceController or some other option.

I'll explain what I'm doing: on a regulated time interval the service will be zipping one hours worth of datafiles from location A and sending the zipped file to location B, this will be done in the background 24/7 or until the service is stopped by the user and runs even when no one is logged in (hence the need for service) I would like the user to be able to pull up a GUI program that will allow them several options:

1) change the location to zip from
2) change the location to zip to
3) manually start the zipping process for a DateTime range specified

Now most of the functions for zipping and timers is all stored within the service. SO im wondering if a ServiceController in the GUI program would allow me to send variables to/from the service (ie folderpath names as strings, various other data) or if I'll need to spend the time making a WCF and treat the GUI as the Client and the Windows service as a source.

It should be noted the GUI will likely recieve data from the service, but only to signify if it is currently busy zipping.


Solution

  • One option is to tave a WCF service embedded on your windows service. With this WCF you can control the behaviour without restarting the service.

    But the best option IMO is to have this in a config file. You can add some keys, but you would have to restart the service when you update the config. In this case you can try a workaround, as in this thread. The config is a good place for this kind of detail, because it can be easily modified and, unlike a database, it will be always avaiable.