简体   繁体   English

如何使用protobuf将ServiceStack服务与非ServiceStack客户端集成?

[英]How to integrate ServiceStack service using protobuf with a non-ServiceStack client?

I would like to use ServiceStack on the server side, and I would like to use protobuf-net as the serialization system used by ServiceStack. 我想在服务器端使用ServiceStack,我想使用protobuf-net作为ServiceStack使用的序列化系统。 However, some of the clients will not be using the ServiceStack client libraries. 但是,某些客户端不会使用ServiceStack客户端库。 They will be using protobuf-net directly. 他们将直接使用protobuf-net。

In reading the widely linked ServiceStack protocol buffers howto ( http://stevenhollidge.blogspot.in/2012/04/servicestack-rest-with-protobuf.html ), it indicates using [DataContract] and [DataMember(Order=i)] attributes on the classes and properties respectively. 在阅读广泛链接的ServiceStack协议缓冲区( http://stevenhollidge.blogspot.in/2012/04/servicestack-rest-with-protobuf.html )时,它表示使用[DataContract]和[DataMember(Order = i)]分别在类和属性上的属性。 However, when I read the protobuf-net documentation it indicates attributes are [ProtoContract] and [ProtoMember(i)] instead. 但是,当我阅读protobuf-net文档时,它表示属性是[ProtoContract]和[ProtoMember(i)]。

If I want my DTOs to work with both native protbuf-net and ServiceStack's protobuf-net wrapper do I need to add both attributes to every class and property, or will one or the other be sufficient? 如果我希望我的DTO与本机protbuf-net和ServiceStack的protobuf-net包装器一起工作,我是否需要为每个类和属性添加这两个属性,或者一个或另一个是否足够?

ProtoBuf requires a mapping from Properties to numerical indexes, both of the options you've specified are equivalent ways to do this: ProtoBuf需要从Properties到数字索引的映射, 您指定的两个选项都是执行此操作的等效方法:

[DataContract]
public class Dto
{
    [DataMember(Order=i)]
    public string PropertyName { get; set; }
}

[ProtoContract]
public class Dto
{
    [ProtoMember(i)]
    public string PropertyName { get; set; }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM