The relationship between a website and a Windows service

I have a website written in C # (MVC) and a Windows service written in C #. Both work on the same machine. The idea is that they can use the same database.

The Windows service acts as an engine, and the website is more of an interface showing the results of calculations performed by the engine. Communication consists of commands with little data from the web server to the Windows service. Very few commands / seconds are expected.

What would be a good way to communicate?

+4
source share
3 answers

Typically, the fastest on the Windows side will be LRPC. Depending on your needs, WCF can be a real problem. We use Win64 LRPC + protobuffers to get about 40 times the data transfer speed from the web server to the background service. It just depends on your needs.

(see Benchmarking WCF versus protocol buffers + RpcLibrary )

protobuf-csharp-port has most of what you need to define the service and messages. Then, using protobuf-csharp-rpc to serialize messages through the Win32 LRPC transport layer .

Once you have finished defining the protocol in protobuffers, it is very simple. Creating a connection and proxy class requires only a few lines of code on the client / server.

Again, it all depends on what you are looking for; however, IMHO is currently not the best RPC architecture for the .NET Framework. Of course, I am biased in my opinion, but we have used variations of this since 2003, and it just works.

PS: If you are building a service from scratch, you can see my guide to Building a Windows Service Project Template . This will allow you to quickly and quickly start with logging, installation and verification at the command line.

+2
source

It all depends on what you want to do. There are several options available: you can host a web service (quiet or not) in a Windows service, you can use Remoting or WCF, etc.

But it all starts with the question: why do you need both? What is stopping you from moving Windows service functionality to a web application?

0
source

You can always do it β€œdifferently” - ask your website to start a web listener and connect to it with the Windows service.

0
source

Source: https://habr.com/ru/post/1385968/


All Articles