document/文档/.net/grpc.md
2024-06-30 04:47:39 +08:00

643 B
Raw Blame History

gRPC服务

## 在已有.net code 中添加gRPC服务器

1.按照包

dotnet add package Grpc
dotnet add package Grpc.Tools
dotnet add package Grpc.AspNetCore

RegionStatisticsClientServer

2.添加 .proto 文件

helloworld.proto

syntax = "proto3";

package HelloWorld;

service Greeter {
  rpc SayHello (HelloRequest) returns (HelloReply) {}
}

message HelloRequest {
  string name = 1;
}

message HelloReply {
  string message = 1;
}

3.配置 csproj 文件

<ItemGroup>
  <Protobuf Include="Protos\helloworld.proto" GrpcServices="Server" />
</ItemGroup>

### 4.生成代码