Question

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.

Était-ce utile?

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

Autres conseils

I don't fully understand what you're trying to say, but you define what the interface to your service is when you make it. If the operations you define take in variables, then you can pass data from your application to the service.

From what you described, just make opertaions in the service to do those 3 things you listed then call those from a button click in your UI code.

WCF would be fine for this here's a basic introduction to it http://msdn.microsoft.com/en-us/library/bb332338.aspx.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top