grpc-dotnet icon indicating copy to clipboard operation
grpc-dotnet copied to clipboard

How to implement a gRPC server in a .Net 6 console app?

Open simmarn opened this issue 2 years ago • 2 comments

I have console applications using WCF that I want to migrate from .Net Framework to .Net 6 (or later). Microsoft recommends that gRPC shall be used. But all tutorials I find are using ASP.NET on the server side. I would really like to see an example on a gRPC server implemented as a .Net 6 console app.

simmarn avatar Nov 11 '23 17:11 simmarn

Related to #1419

hawkerm avatar Nov 11 '23 22:11 hawkerm

Possibly I misunderstand the question but just make a console app in eg. net6.0, add package Grpc.AspNetCore.Server, use var builder = WebApplication.CreateBuilder(args); Everything else is the same.

osexpert avatar May 09 '24 20:05 osexpert

Nothing on this still?

just-ero avatar Sep 23 '24 08:09 just-ero

A console app can use AspNetCore and host a grpc server. So the question is probably "How to implement a gRPC server without AspNetCore?", but this is the same question as https://github.com/grpc/grpc-dotnet/issues/1419 so I suggest resolve this as duplicate.

osexpert avatar Sep 23 '24 08:09 osexpert

Appreciate @JamesNK response here outlining more of the underlying structure of the project here: https://github.com/grpc/grpc-dotnet/issues/1419#issuecomment-2367608784

The current Grpc.AspNetCore solution works in most scenarios:

Can you use Grpc.AspNetCore in a console app? Yes. Can you use Grpc.AspNetCore in a WinForms app? Yes. Can you use Grpc.AspNetCore in a WPF app? Yes. Can you use Grpc.AspNetCore in a WinUI 3 app? Yes.

So agree #1419 can be closed as it answers that original question, but I believe this issue should remain open as it's asking for the actual advice/doc/example on how to perform one of the above scenarios.

I think the issue here is we just need the basic sample to show how to host the server in these other application types like a Console or WPF/WinUI app, where the app.Run() from an AspNetCore app builder is not the main entry point of the server program.

Being a non-AspNetCore dev and coming from other/prior solutions or looking at other language implementations, this is the gap here in understanding and the questions/confusion on these threads/issues. We're just looking for the docs/examples for non-web-first scenarios and how to marry these things together.

If there is an example for this already, it's not easily discoverable or findable as they all seem to leverage the same setup of being the main host executable for the server.

hawkerm avatar Sep 24 '24 07:09 hawkerm