.net5 grpc 及 grpcui使用

发布时间 2023-04-26 15:06:25作者: Hey,Coder!
  1. 创建项目

  2. 根据vs提供的模板生成给结构如下

至此grpc服务已经准备完成

grpcui

grpcui需要使用到反射,需要手动安装nuget包【Grpc.AspNetCore.Server.Reflection】(不安装这个包会报错Failed to compute set of methods to expose: server does not support the reflection API)
随后在startup文件中的ConfigureServices方法内添加

services.AddGrpcReflection();

在Configure方法的app.UseEndpoints调用中添加

endpoints.MapGrpcReflectionService();

启动服务后即可通过下载的grpcui.exe访问,参数入下

grpcui.exe -plaintext localhost:5000

将会打开网页工具来调试

grpcui.exe下载