Reputation: 88
Hi my datacontract has inheritance, but the last member is not accessible when consuming the service:
namespace Services.SearchService
{
[DataContract]
[KnownType(typeof(LabellingSearch))]
public class SearchResult
{
[DataMember]
public int ID { get; set; }
[DataMember]
public string Title { get; set; }
[DataMember]
public DateTime Modified { get; set; }
}
/// <summary>
/// Specialist Search Result for Labelling Content Data
/// </summary>
[DataContract]
[KnownType(typeof(Labelling))]
public class LabellingSearch : SearchResult
{
[DataMember]
public string Region { get; set; }
[DataMember]
public string Country { get; set; }
[DataMember]
public string LabelSummary { get; set; }
}
/// <summary>
/// Full Labelling Content Data
/// </summary>
[DataContract]
public class Labelling : LabellingSearch
{
public string Content { get; set; }
}
}
so in the consuming class I can access the type 'Labelling' but I can't get at its 'Content' property.
Upvotes: 0
Views: 640
Reputation: 12535
You can't access to Content
property because it's not DataMember
so it's not serialized. Add [DataMember]
attribute
[DataMember]
public string Content { get; set; }
From MSDN about DataMemberAttribute Class:
When applied to the member of a type, specifies that the member is part of a data contract and is serializable by the DataContractSerializer.
Upvotes: 1
Reputation: 316
You didn't put that member of the class as [DataMember]
[DataContract]
public class Labelling : LabellingSearch
{
[DataMember]
public string Content { get; set; }
}
Upvotes: 2