Protobuf.net WCF反序列化列表

我尝试使用带有protobuf-net r.282的WCF

好。 我用ProtoBehavior属性标记我的合同

[OperationContract,ProtoBehavior] [FaultContract(typeof(ServiceFaultException))] Dictionary GetSalesTemplates(); [OperationContract, ProtoBehavior] [FaultContract(typeof(ServiceFaultException))] List GetActivities(); 

接下来, – DTO:

  [DataContract] [Serializable] [ProtoContract] public class ActivityCategoryDTO { [DataMember] [ProtoMember(1)] public int Id { get; set; } [DataMember] [ProtoMember(2)] public string Guid { get; set; } [DataMember] [ProtoMember(3)] public string Name { get; set; } } 

我尝试从客户端使用此服务。 当我调用GetSalesTemplates时 – 一切正常。 我有成功的反序列化字典,但当我调用GetActivities时,我在客户端得到null。 通过提琴手,我看到,数据成功传输,所以我认为这是解串器问题。

怎么了? 如何在客户端获取列表?

编辑

似乎我的所有列表都有问题:)

 [DataContract] [Serializable] [ProtoContract] public class SalesTemplateDTO { [ProtoMember(1)] [DataMember] public string Name { get; set; } [ProtoMember(2)] public List Fields; } 

客户端只有Name,List of Fields再次为null。 虽然所有数据都是传输的。

好; 我已经复制了,这实际上看起来是IDE / svcutil拒绝重新使用DTO程序集中的服务契约(接口),即使它正在重用数据契约(类)。 mex生成的服务契约(接口)缺少必要的额外属性,因此protobuf-net 永远不会被要求反序列化

两种选择:

选项1

使用配置而不是代码来定义protobuf用法; 这样做的好处是可以在不对客户端服务器进行任何更改的情况下使用它。

选项2

不要使用生成的服务包装器 – 通用对应物可以简单地写为:

 public class Client : ClientBase where T : class { public T Service { get { return Channel; } } public Client() { } public Client(string endpointConfigurationName) : base(endpointConfigurationName) { } public Client(string endpointConfigurationName, string remoteAddress) : base(endpointConfigurationName, remoteAddress) { } public Client(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : base(endpointConfigurationName, remoteAddress) { } public Client(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : base(binding, remoteAddress) { } } 

然后消费为:

 using (var svc = new Client()) { var data = svc.Service.GetActivities(); } 

我不知道我的头脑; 我可以调查,但此刻并不正确。 作为一个实用的解决方法(直到我能找到原因),或许返回类似于包含 List作为成员的ActivityResult类?