开发者

Is it possible to define derivative classes that are DataContract?

开发者 https://www.devze.com 2023-02-18 15:30 出处:网络
Is this code can be possible in WCF ? The object base and derivativeObjectare both object that will be sen开发者_C百科d to the client.

Is this code can be possible in WCF ? The object base and derivativeObject are both object that will be sen开发者_C百科d to the client. I tested this and i getting an exception - but i'm not sure this is something prohibition in WCF.

[DataContract]
public class base
{
    [DataMember]
    public string Key { get; set; }

    [DataMember]
    public string ID { get; set; }
}

[DataContract]
public class derivativeObject : base
{
    [DataMember]
    public string Name { get; set; }
}


Looking to use Known Types (and the KnownTypeAttribute) perhaps?

[DataContract]
[KnownType(typeof(SalesPerson))]
public class Person
{
  [DataMember]
  public string Name { get; set; }
}

[DataContract]
public class SalesPerson : Person
{
  [DataMember]
  public double Commission { get; set; }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消