简体   繁体   English

在 Windows 窗体应用程序中托管 gRPC 服务

[英]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.我想创建一个 gRPC 服务,但我需要在一个 winform .net 应用程序中托管。 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 ...有一个关于如何在 Windows 窗体应用程序中托管 ASP.NET Core API的非凡示例,我希望有人向我解释,在该示例中我需要安装什么以及我应该更改什么,以便以以下形式托管 grpc 服务窗户...

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.安装包 Microsoft.AspNetCore.Grpc.HttpApi 这会将您的 gRPC 端点映射到经典 HTTP。 It is not automatic you need to specify the services in the Startup.cs as follow:您需要在 Startup.cs 中指定服务不是自动的,如下所示:
    app.UseEndpoints(endpoints =>
            {
                endpoints.MapGrpcService<MygRPCService>();
            });
  1. Into your protos you need to indicate the HTTP path, something like this:在您的 protos 中,您需要指明 HTTP 路径,如下所示:
     rpc Get(GetRequest) returns (GetReply) {
        option (google.api.http) = {
          get: '/my-endpoint'
          body: '*'
        };
      }
  1. Add to your Startup.cs ConfigureService method:添加到您的 Startup.cs ConfigureService 方法:
    services.AddGrpc();
    services.AddGrpcHttpApi(); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM