无法生成gRPC

太子

我目前正在尝试在现有的C#ASP .NET Core应用程序中实现gRPC服务器。但是并没有生成C#绑定以在应用程序中使用。我已经安装了以下依赖项:

  • Grpc
  • Google.Protobuf
  • Grpc.Core
  • Grpc。工具

我已将.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) {}
} 

我曾尝试清洁和重建,但无济于事。它可能有点小,我在某个地方不见了,但我不确定它是什么。有人有主意吗?

安静的张

您需要编辑csproj,例如默认的greet.proto会执行以下操作:

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

GrpcServices参数也可以是ClientBoth取决于您的需求。

如果您使用的是Visual Studio 2019,则还可以使用构建操作来执行此操作。右键单击您的原型文件,然后选择属性。选择Protobuf compilerBuild Action

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章