2

How do I consume windows background service in my Blazor .net 6 web application.

I have created two projects, one is a background service and it is running on my machine and another is a Blazor web application. So How do I call running windows service in my web application?

H H
  • 263,252
  • 30
  • 330
  • 514
  • **Exactly** what kind of interaction with the Windows Service are you thinking of? A Windows Service is the Win32 equivalent of a *nix daemon: it's just a userland process that runs - there is no requirement it offer any kind of API to other processes running in the same box. – Dai Oct 10 '22 at 15:26
  • Your blazor web application runs on the client/browser and the server, from which side do you want to call the Windows service? You can't call a local service from inside a browser! that violates the whole browser principle and internet security. Technically you can call a Windows service from a web application running on a server but that is highly suspicious and not conventional – Siraf Oct 11 '22 at 07:50

1 Answers1

0

Its generally not a good idea to "call a windows service" directly. If you want your background service to respond to web requests it should be hosted in IIS or kestrel, and called like a regular api. This is idea if you expect a response from your request. Otherwise I would suggest using a message broker such as rabbit mq to dispatch a request. Ideally the message would be sent by an endpoint exposed with your blazor app.

Jay
  • 6,224
  • 4
  • 20
  • 23
  • 2
    There’s no need to add a dependency on RabbitMQ when Windows has its own dependable MSMQ built-in: https://stackoverflow.com/q/400115/159145 – Dai Oct 10 '22 at 16:14
  • @Dai True. I never said "must use rabbit", just "use a message broker such as..." but I would never use MSMQ for a production build. – Jay Oct 10 '22 at 19:26
  • May I ask what your reservations about MSMQ are? – Dai Oct 10 '22 at 20:08