GRPC:将消息proto变成列表< message> (c#.net6)
我想将一个从协议缓冲区的MessagerSponse变成一个 iEnumerable< messageresponse>
因此,在服务中,我将返回我一个iEnumerable< messageresponse>
proto我拥有:
syntax = "proto3";
option csharp_namespace = "ProjectName.Protos";
package Banana;
service Banana {
rpc GetAllBananas (MessageRequest) returns (ListBananasResponse);
}
//How to Turn this to IEnumerable<> ?
message ListBananasResponse{
string bananaName = 1;
string bananaInfo = 2;
}
message MessageRequest{
string message = 1;
}
这是我的bananaservice.cs
using Grpc.Core;
using ProjectName.Protos;
namespace ProjectName.Services
{
public class BananaService : Banana.BananaBase
{
//The Method should return a IEnumerable list of bananas
//want to do Task<IEnumerable<ListBananasResponse>>
public override Task<ListBananasResponse> GetAllBananas(MessageRequest request,
ServerCallContext context)
{
var lstbananas = new IEnumerable<ListBananasResponse>();
return lstbananas;
}
}
有什么办法可以做到这一点,如果是这样,该怎么做? (我正在使用c#.net6)
任何答案都受到欢迎:)
I want to turn a messageResponse from a protocol buffer into aIEnumerable<messageResponse>
so in the service will return me an IEnumerable<messageResponse>
Proto I have:
syntax = "proto3";
option csharp_namespace = "ProjectName.Protos";
package Banana;
service Banana {
rpc GetAllBananas (MessageRequest) returns (ListBananasResponse);
}
//How to Turn this to IEnumerable<> ?
message ListBananasResponse{
string bananaName = 1;
string bananaInfo = 2;
}
message MessageRequest{
string message = 1;
}
And this is my the BananaService.cs
using Grpc.Core;
using ProjectName.Protos;
namespace ProjectName.Services
{
public class BananaService : Banana.BananaBase
{
//The Method should return a IEnumerable list of bananas
//want to do Task<IEnumerable<ListBananasResponse>>
public override Task<ListBananasResponse> GetAllBananas(MessageRequest request,
ServerCallContext context)
{
var lstbananas = new IEnumerable<ListBananasResponse>();
return lstbananas;
}
}
Is there any way to do this and if so, how to do it? (I'm Using C# .Net6)
Any answer is welcome :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有办法指定Protobuf RPC一次返回响应列表。这里有两个选项:
除非您实际需要流式流,否则 前者的方法。因此
。
There's no way of specifying that a protobuf RPC returns a list of responses in one go. There are two options here:
Unless you actually need streaming, I'd strongly advise the former approach. So your .proto file would include a section like this:
You'd then implement the RPC with something like: