Is it possible to have optional DataMembers in WCF?
If I have the following class:
[DataContract]
public class GetColorsRS
{
[DataMember(Name = "Colors", Order = 0, IsRequired=true)]
public List<Color> Colors { get; set; }
[DataMember(Name = "Errors", Order = 1, IsRequired=false)]
public List<Error> Errors { get; set; }
}
If no errors are found in the request, I want to send back a response that does not have an Errors node, however, it passes back an Errors node that is empty. I thought this is what the IsRequired was for?
Just noticed EmitDefaultValue, is this what开发者_StackOverflow中文版 I am looking for?
I have determined that EmitDefaultValue
should be set to false if I don't want to serialize the default value of the DataMember.
[DataMember(Name = "Errors", Order = 1, IsRequired=false,EmitDefaultValue=false)]
public List<Error> Errors { get; set; }
精彩评论