3

I created the GrpcGreeter and GrpcGreeterClient projects in Visual Studio 2019 from the following page:

[https://learn.microsoft.com/en-us/aspnet/core/tutorials/grpc/grpc-start?view=aspnetcore-5.0&tabs=visual-studio][1]

The only change I made to these examples was that in order for the GrpcGreeter app to run as a Windows service, I added ".UseWindowsService()" to IHostBuilder CreateHostBuilder. I published both to local folders while in VS, and selected Self Contained for the Deployment Mode.

Server and client work fine using https://localhost:5001 when run from the either the VS environment or when running the published GrpcGreeter.exe and GrpcGreeterClient.exe directly.

I then used "Sc create" to successfully create a Windows service with GrpcGreeter.exe. Then on the Services window I started the service.

The problem is that when run as a Windows service the GrpcGreeter.exe does not listen on port 5001, as shown with netstat -anb (it does listen to port 5354, apparently). And of course when I then run GrpcGreeterClient.exe it does not connect. When GrpcGreeter.exe is run not as a Windows service netstat shows that it is listening to 5001, and GrpcGreeterClient.exe talks to it just fine.

A look at Event Viewer shows 3 errors happening immediately whenever I start the service on the Services window. I'm abbreviating them below.


1st: Faulting application name: GrpcGreeter.exe, version: 1.0.0.0, time stamp: 0x5f6b3846 Faulting module name: ntdll.dll, version: 10.0.19041.546, time stamp: 0xd49544eb Exception code: 0xc0000374 Fault offset: 0x000e6763 ...

2nd: Fault bucket , type 0 Event Name: FaultTolerantHeap Response: Not available Cab Id: 0

Problem signature: P1: GrpcGreeter.exe ...

3rd: Fault bucket 2242750238749681031, type 1 Event Name: APPCRASH Response: Not available Cab Id: 0

Problem signature: P1: GrpcGreeter.exe ...


Please help. Thank you.

TomV
  • 31
  • 3
  • 1
    5354 is usually the multicast DNS responder, so I'm not convinced that's *your* code listening on that port. – paxdiablo Nov 11 '20 at 22:11
  • The same issue, I opened the port 5001 in EC2 security groups but still can't connect from local. but no error on windows events after starting the service. any clue? – Karvan Jan 04 '21 at 15:53

1 Answers1

0

this is a very old post but I too came across with this issue when deploying a windows service with gRPC. Not sure will it solve your problem or not but my issue was that when you deploy into the windows service, it needs to have a certificate configured. It was stated in this documentation here under the "Set HTTPS certificates by using configuration" part

So I have created a self signed certificate using openssl where you can refer here too, then just add the .pfx file into the kestrel configuration as shown by the Microsoft documentation, build it and publish it as a windows service. After that, just proceed with the normal service creation procedure using

sc create 
// and then
sc start

The windows service should now be running with the gRPC server without any issue (For my case at least). One thing to note is that because this is a self signed certificate which is not exactly trustable, when the frontend attempts to communicate with the server, it will have an error about the cert. You just need to trust it and it will be fine.

On browser, just go to the link that is hosting the gRPC, for example https://localhost:5001, click advanced and trust it.

In my case, I was using electron + angular so I just need to add this code snippet that I have gotten from here. Now my frontend can communicate with the gRPC server in the windows service normally.

// ignore self signed certificate in dev mode
    if (process.env.NODE_ENV === 'development') {
        // SSL/TSL: this is the self signed certificate support
        app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
            // On certificate error we disable default behaviour (stop loading the page)
            // and we then say "it is all fine - true" to the callback
            event.preventDefault();
            callback(true);
        });
    }
Dharman
  • 30,962
  • 25
  • 85
  • 135
the newbie coder
  • 652
  • 2
  • 8
  • 27