Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hosting gRPC service in a Windows Forms Application

I want to create a gRPC service but I need to host in a winform .net application. there is an extraordinary example of how Hosting ASP.NET Core API in a Windows Forms Application I would like someone to explain to me, what I need to install and what I should change in that example, to host a grpc service in the form of Windows ...

like image 254
Fabian Wesling Avatar asked Dec 21 '25 00:12

Fabian Wesling


1 Answers

You could follow the same steps but with several additional:

  1. Install the package Microsoft.AspNetCore.Grpc.HttpApi This is going to map your gRPC endpoints to the classical HTTP. It is not automatic you need to specify the services in the Startup.cs as follow:
    app.UseEndpoints(endpoints =>
            {
                endpoints.MapGrpcService<MygRPCService>();
            });
  1. Into your protos you need to indicate the HTTP path, something like this:
     rpc Get(GetRequest) returns (GetReply) {
        option (google.api.http) = {
          get: '/my-endpoint'
          body: '*'
        };
      }
  1. Add to your Startup.cs ConfigureService method:
    services.AddGrpc();
    services.AddGrpcHttpApi(); 
like image 139
Jesus Santander Avatar answered Dec 23 '25 15:12

Jesus Santander



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!