document/.net/grpc.md
2024-05-31 17:55:08 +08:00

46 lines
643 B
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# gRPC服务
## 在已有.net code 中添加gRPC服务器
### 1.按照包
```C#
dotnet add package Grpc
dotnet add package Grpc.Tools
dotnet add package Grpc.AspNetCore
```
RegionStatisticsClientServer
### 2.添加 .proto 文件
helloworld.proto
```C#
syntax = "proto3";
package HelloWorld;
service Greeter {
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
message HelloRequest {
string name = 1;
}
message HelloReply {
string message = 1;
}
```
### 3.配置 csproj 文件
```C#
<ItemGroup>
<Protobuf Include="Protos\helloworld.proto" GrpcServices="Server" />
</ItemGroup>
```
### 4.生成代码
###
```C#
```