GRPC 服务可以返回其中包含空值的列表吗?

问题描述 投票:0回答:1

我有一个在不同端口上使用各种不同协议托管的服务(Rest on 5000,protobuf-net with Grpc.Core on 12000,WcfCore with net.tcp Binding on 19000,protobuf-net with Grpc.AspNetCore.Server 26000)。

服务返回

List<string>
,如果列表已填满(例如
{ "1", "2", "3", "4", "5", }
),则它适用于所有服务。一旦列表中的内容为空(例如
{ "1", "2", null, "3", "4", "5", null }
),Grpc 服务(端口 12000 和 26000)都会失败。通过 Grpc 传输这是无效的吗?

我不确定是否需要说,但只要是实例化的字符串,就可以。因此,以上面的示例为例,如果我用空字符串替换空值,

{ "1", "2", "", "3", "4", "5", "" }
,那就有效了。

c# grpc protobuf-net
1个回答
0
投票

我相信这涵盖了它:支持空值和空集合,请参阅大约一半的集合部分。

阅读该页面,但作为摘要,这是示例:

[ProtoContract]
class SomeMessage
{
    // *similar* to (but with field-presence)
    // repeated .google.protobuf.Int32Value values = 6;
    [ProtoMember(6), NullWrappedValue]
    public List<int?> Ids {get;} = new();

    // likewise, but using field-presence in an artifical
    // message type that has: SomeOtherMessage value = 1;
    [ProtoMember(7), NullWrappedValue]
    public List<SomeOtherMessage> Items {get;} = new();

    // as with Items, but applied to the value portion of the
    // key/value pairs
    [ProtoMember(8), NullWrappedValue]
    public Dictionary<int, SomeOtherMessage> KeyedItems {get;} = new();
}
© www.soinside.com 2019 - 2024. All rights reserved.