如何在WCF中爲抽象類定義DataContract?在抽象類中使用WCF
我有一個類「人」,我使用WCF成功溝通。現在我添加一個從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; }
}
完美。非常感謝你! – 2013-12-04 10:38:51