views:

420

answers:

2

I have a windows service running as part of my application.

If I wish to communicate with it via the service handle I can issue custom commands (eg, 'start worker'). Ultimately, this will be a call to the Win32 ControlService() function. What is the best way to return a block of data from such a command?

Specifically, I want to return a 'default URL' (ie a string) my service will respond on via other protocols like http.

A solution that is straightforward to implement in a C# (.net 2.0) service would be preferred.

A: 

Have you looked into WCF? You'd have to go to .NET 3.0 or above, but you can easily configure your services to run over TCP/IP, or HTTP, etc.

rie819
+1  A: 

If you want to stay with .net 2.0, use remoting. Let windows handle the ControlService calls (for starting/stopping/pausing your service). When you want your app to connect, establish a remoting connection to your service. Works great.

Alternatives: If you can move up to .net 3.5, you could use WCF instead of remoting.

You could use low-level communications (pipes and sockets), but really, remoting should be easier and work very well -- and it's supported in .net 2.0.

JMarsch
My brief scan of the remoting docs suggests that it is exposed to the network, with all the security implications of that. I only need a solution which works on the local machine.
John McAleely
@John McAleelyI believe that you can use the InterprocessCommunication channel: System.Runtime.Remoting.Channels.Ipc if you want to ensure that only local processes can access your remotable objects.
JMarsch
Ah, yes - that looks ideal. I missed the fact it didn't use the network on my first read of the documentation.
John McAleely