views:

123

answers:

3

I have written a windows service in C# that gathers performance, disk and memory information and writes it to the EventLog. It is enabled as a network service. What I would like to do is be able to gather this information from a remote location. This service will run at various client machines and I would like to retrieve this information periodically (once a day) and store them in a database table. I am confused as to how one can query a windows service over a network. In other words, what exactly makes the service a "Network Service"?

I do not want the service to directly connect to my database and write this information. But I would like to initiate it from a remote machine, retreive the information and then write that information to my database table.

I was unable to find any tutorial that illustrates a networked windows service. Most of them covered writing to event logs and I am pretty much stuck there.

Is this doable, are there any suggestions about how this sort of stuff is done?

+1  A: 

Use WCF to enable some form of a RESTful Web Service.

See wcf-getting-started on MSDN, and specially A Guide to Designing and Building RESTful Web Services with WCF.

gimel
+1  A: 

AFAIK 'Network Service' just means that it is running under the "Network Service" account which has a different set of permission than the 'Local Service' or 'System' accounts.

To expose a service to another machine on the network however (apart from the standard STOP, START, RESTART functionality that you get through the services snap-in - services.msc) you will need to create your service using something like Remoting, Webservices or most ideally as gimel mentioned WCF.

mundeep
+2  A: 

If the other suggestions to move over to WCF Web services are not an option, you can do allot with Custom commands in a windows service without having to resort to remoting.

Effectively you can send an integer between 128 & 256 and then have your service execute whatever code you need it to when it receives that command, like sending all the information to your database or web service.

You will be able to initiate it from your side as and when you need to while the service happily trundles along on the client machines.

Take a look at this code project article for an example: Creating a Basic Windows Service in C#

Take a look at the OnCustomCammand method.

Here's another example article from Microsoft: Communicate With Windows Services

Gineer