asp.net-core - 将 gRPC proto 文件定义包含到单个 proto buf 文件中时,为什么会出现 C# 编译器错误?
问题描述
我正在为 .NetCore gRPC 应用程序构建一系列 ProtoBuf 定义。我正在使用 Orchestrator 模式,因为我将创建一系列微服务。
我的原型定义遇到问题,将编译器错误视为“未定义”。这些定义位于几个不同的文件中(具有不同的 C# 命名空间)。以下是我的定义的简化版本。
考虑以下 protobuf 文件:
服务.proto
syntax = "proto3";
option csharp_namespace = "RequestHandlerService";
package test;
service Handler
{
rpc AddItem1(G_RequestType1) returns (G_RequestResponse) { }
rpc AddItem2(G_RequestType2) returns (G_RequestResponse) { }
}
message G_RequestType1{
string originId = 1;
string request = 2;
}
message G_RequestType2{
string originId = 1;
string request = 2;
}
message G_RequestResponse{
string response = 1;
}
windowsservice.proto:
syntax = "proto3";
import "google/protobuf/timestamp.proto";
option csharp_namespace = "Windows.RequestHandler.Service";
package windows.requesthandler.service;
service WindowsHandler
{
rpc Action1(G_Action1Request) returns (G_Action1Response) { }
rpc Action2(G_Action2Request) returns (G_Action2Reponse) { }
}
message G_Action1Request{
string transactionId = 1;
google.protobuf.Timestamp DateTimeStamp = 2;
string filePath = 3;
}
message G_Action2Request{
string transactionId = 1;
google.protobuf.Timestamp DateTimeStamp = 2;
string textToInsert = 3;
}
message G_Action1Response {
google.protobuf.Timestamp DateTimeStamp = 1;
string fileSecurityStatusMessage = 2;
G_Action1Request action1Request = 3;
}
message G_Action2Response {
google.protobuf.Timestamp DateTimeStamp = 1;
string fileModifierStatusMessage = 2;
G_Action2Request action2Request = 3;
}
message G_WindowsRequest {
int32 requestId = 1;
oneof RequestType{
G_Action1Request action1Request = 2;
G_Action2Request action2Requestion = 3;
}
}
message G_WindowsRequestResponse {
bool wasSuccessful = 1;
string response = 2;
oneof ResponseType{
G_Action1Response action1Response = 3;
G_Action2Response action2Respone = 4;
}
}
Orchestrator.proto
syntax = "proto3";
option csharp_namespace = "OrchestratorService";
package test;
import "service.proto";
import "windowsservice.proto";
service Orchestrator
{
rpc RegisterClient(G_RegisterClientRequest) returns (stream G_Response) { }
rpc EnqueueRequest(G_OrchestrationRequest) returns (G_Response) { }
}
message G_OrchestrationRequest{
string originId = 1;
oneof RequestType{
G_RequestType1 requestType1 = 2;
G_RequestType2 requestType2 = 3;
G_Response response = 4;
G_WindowsRequest windowsRequest = 5;
G_WindowsRequestResponse windowsRequestResponse = 6;
}
}
message G_RegisterClientRequest{
string clientId = 1;
}
message G_Response{
bool wasSuccessful = 1;
string response = 2;
}
这是我的 Orchestrator 项目的 csproj 文件中的定义:
<ItemGroup>
<Protobuf Include="../Protos/orchestrator.proto" GrpcServices="Server" ProtoRoot="../Protos/">
<Link>Protos/orchestrator.proto</Link>
</Protobuf>
<Protobuf Include="../Protos/service.proto" GrpcServices="Client" ProtoRoot="../Protos/">
<Link>Protos/service.proto</Link>
</Protobuf>
<Protobuf Include="../Protos/windowsservice.proto" GrpcServices="Client" ProtoRoot="../Protos/">
<Link>Protos/windowservice.proto</Link>
</Protobuf>
</ItemGroup>
G_WindowsRequest和G_WindowsRequestResponse都引发编译器错误,说明它们未定义。这是csharp_namespace和/或包解析的问题吗?
有没有办法在单独的原型定义中强制执行单独的包/csharp_namespace 定义,但在汇总的“协调器”原型文件定义中引用这些定义?
这是我看到的编译器错误的片段:
2> orchestrator.proto(22,5): error : "G_WindowsRequest" 未定义。2> orchestrator.proto(23,5): 错误:未定义“G_WindowsRequestResponse”。2>在项目“Protos.csproj”中完成构建目标“_Protobuf_CoreCompile”——失败。2> 2>完成构建项目“Protos.csproj”——失败。2> 2>构建失败。2> 2>orchestrator.proto(22,5): 错误:“G_WindowsRequest”未定义。2>orchestrator.proto(23,5):错误:未定义“G_WindowsRequestResponse”。2> 0 个警告 2> 2 个错误
解决方案
推荐阅读
- php - WooCommerce:当免费送货可用时,隐藏除本地取货外的其他送货方式
- python - 如何解决 Pandas 合并错误:键必须是整数或时间戳?
- reactjs - 如何将其转换为使用我已经到位的代码?
- c# - URL 中页面名称后所有路径的 ASP.NET Core Razor 页面端点路由
- text-files - 如何删除打印的文本文件中的引号
- angular - Angular http get 请求什么也不做
- php - 在 Google Cloud 中使用 Laravel 8 的 Docker 容器的 503“服务不可用”
- c - 如何监控文件系统路径名在 C 或 inotify 中被重命名?
- python - 如何删除多个文件名中的所有空格?
- python - 从具有特定 id 的 div 开始获取嵌套的 div 内容