How to communicate between Windows Services

2019-04-08 02:43发布

I have 2 windows services that I created using C#.

I would like one of the services to call a function in the second windows service.

How should I do it?

EDIT:

The issue is That I have to application that running ( I don't need them to be Rather service Process is good too) but I need this 2 application to communicate, this 2 application are on the same server,

3条回答
贼婆χ
2楼-- · 2019-04-08 03:07

Sure. There are a bunch of IPC mechanisms you could use. Remoting, TCP/HTTP Listeners, etc.

Does either service provide functionality that might be useful outside of the other service?

See this thread for more ideas: IPC Mechanisms in C# - Usage and Best Practices

EDIT: As Davide Piras pointed out, if WCF is available for you to use, then consider using it. It will simplify life. The WCF configuration files are sometimes a pain to wield, but there's a nice tool for that too: http://msdn.microsoft.com/en-us/library/ms732009.aspx

查看更多
姐就是有狂的资本
3楼-- · 2019-04-08 03:20

I found all the other answers correct but a little too much complicated (WCF is a big deal) and not scalable (memory and named pipes will only work on the same sever). I suggest you DotNetMQ messaging system. It's easy to use and deploy and let's you communicate even between processes running on different servers.

查看更多
SAY GOODBYE
4楼-- · 2019-04-08 03:21

Are the services on the same box? Do you have .NET 4? Highly recommend using the fastest mode possible, memory-mapped files.

If they're on the same box, but you don't have .NET 4, or are in a homogenous Microsoft Windows network, named pipes could work. More to the point, I'd use WCF over a named pipe.

查看更多
登录 后发表回答