Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to communicate between Windows Services

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,

like image 338
MoShe Avatar asked Jan 23 '12 14:01

MoShe


People also ask

Can two Windows services have the same name?

No, you should not have 2 services with the same name. It is mentioned in the Service Configuration Guide that service names should be unique.

How do Windows services work?

Microsoft Windows services, formerly known as NT services, enable you to create long-running executable applications that run in their own Windows sessions. These services can be automatically started when the computer boots, can be paused and restarted, and do not show any user interface.

How do you call a Windows service method in C#?

Choose "Visual C#" >> "Windows" project type and select "Windows Service" from the right hand side and name the project "TestWindowsService" as shown in the following screenshot. After you click "OK", the project will be created and you will see the design view of the service as shown in the following screen.

What are the different window services?

Windows Services broadly fall into three categories depending on the actions and applications they control: Local Services, Network Services and System. Third party applications such as antivirus software may also install their own services.


2 Answers

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

like image 115
jglouie Avatar answered Sep 27 '22 16:09

jglouie


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.

like image 20
Jesse C. Slicer Avatar answered Sep 27 '22 18:09

Jesse C. Slicer