【发布时间】:2011-03-07 07:36:03
【问题描述】:
如何在 WCF 中为抽象类定义 DataContract?
我有一个使用 WCF 成功通信的“Person”类。现在我添加一个从 Person 引用的新类“Foo”。一切都还好。但是当我使 Foo 抽象并定义一个子类时,它会失败。它在服务器端失败并出现 CommunicationException,但这并不能告诉我太多。
我为测试而制作的简化类:
[DataContract]
public class Person
{
public Person()
{
SomeFoo = new Bar { Id = 7, BaseText = "base", SubText = "sub" };
}
[DataMember]
public int Id { get; set; }
[DataMember]
public Foo SomeFoo { get; set; }
}
[DataContract]
public abstract class Foo
{
[DataMember]
public int Id { get; set; }
[DataMember]
public string BaseText { get; set; }
}
[DataContract]
public class Bar : Foo
{
[DataMember]
public string SubText { get; set; }
}
【问题讨论】:
标签: .net wcf abstract-class datacontract