2

I have a windows services project consisting of two services, service1 and service2. How can we communicate between the two services? For example, how can we have have service2 started by service1? Can I use the ServiceController class to do this? What would you suggest to do this?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Saeid
  • 13,224
  • 32
  • 107
  • 173

2 Answers2

7

The ServiceController class includes an ExecuteCommand methods that takes an int. Your two services could therefore communicate by sending ExecuteCommand messages to each other if you can get away with very limited parameters.

However, as the other poster comments, WCF may be a better answer. You can create named pipes or use HTTP between the two services. Two good tutorial pages can be found below.

Basic WCF Tutorial with examples

More complex WCF, if you wanted to 'fake' delegates for example

Hope that helps.

Jim Grimmett
  • 661
  • 6
  • 10
6

If "comunication" you mean just to start and stop Service2, than yes, ServiceController should be used.

If you need other type of comunication, like sending some data from one to another,than ServiceController will not help, you should use WCF

Hope this helps

Arsen Mkrtchyan
  • 49,896
  • 32
  • 148
  • 184