我目前正在尝试在现有的 C# ASP .NET Core 应用程序中实现 gRPC 服务器。但不会生成 C# 绑定以在应用程序中使用。我已经安装了以下依赖项:
我已将该.proto文件添加到Protos我的项目中的文件夹中。我有以下.proto配置:
syntax = "proto3";
//Request that comes through from the microservice endpoint
message RegistrationRequest {
string type = 1;
string ipAddress = 2;
}
//Response on the service register endpoint
message RegistrationResponse {
bool accepted = 1;
}
//Request to get API endpoint to use based on type
message HostRequest {
string type = 1;
}
//Response of the host request
message HostResponse {
string ipAddress = 1;
}
//Service for the repository
service ServiceRepoServer {
//Method that will register the endpoint on the repo
rpc RegisterEndpoint (RegistrationRequest) returns (RegistrationResponse) {}
//Method that will return an endpoint based on type
rpc RequestEndpoint (HostRequest) returns (HostResponse) {}
}
Run Code Online (Sandbox Code Playgroud)
我尝试过清理和重建,但没有成功。这可能是我在某个地方丢失的一些小东西,但我不确定它是什么。有人有主意吗?
Lei*_*ang 10
您需要编辑csproj,例如默认的greet.proto会执行以下操作:
<ItemGroup>
<Protobuf Include="Protos\greet.proto" GrpcServices="Server" />
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
GrpcServices参数也可以是Client或Both取决于你需要什么。
如果您使用的是 Visual Studio 2019,还可以使用构建操作来执行此操作。右键单击您的原型文件并选择属性。选择Protobuf compiler在Build Action