以下是在运行protobuf-net版本2.0.0.480的WCF环境中工作和不工作的类定义。
知道处理代码使用实际类型填充响应列表,在本例中为SomeClassRow。
更奇怪的是,对于SomeResponse的糟糕版本,WCF有时会工作,有时却没有。
这就是我使用IDataRow界面的原因。这使我的响应列表可以保存任何类型的行。
所以问题是,为什么protobuf在使用强类型与接口(IDataRow)定义列表时无法反序列化?
Thanks,
Ninos
[ProtoContract]
[ProtoInclude(101, typeof(BaseClassInfo))]
public interface IDataRow
{
}
[ProtoContract]
[ProtoInclude(101, typeof(SomeClassRow))]
public class BaseClassInfo : IDataRow
{
[ProtoMember(1)]
public int SomeId { get; set; }
...
}
// This version of the class won't work because it defines the collection with the
// strongly type name i.e. List<Some
[ProtoContract]
public class SomeResponse
{
[ProtoMember(1)]
public List<SomeClassRow> Rows { get; set; }
...
}
// SomeClassRow is in turn an IDataRow.
[ProtoContract]
public class SomeClassRow : BaseClassInfo
{
[ProtoMember(1)]
public string Name { get; set; }
[ProtoMember(2)]
public int Value { get; set; }
...
}
// But, if the response is defined as follows then the WCF deserializes correcty and ALWAYS.
[ProtoContract]
public class SomeResponse
{
[ProtoMember(1)]
public List<IDataRow> Rows { get; set; }
...
}