开发者

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; }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜