Last post Aug 04, 2014 10:58 AM by Siva Krishna Macha
Aug 04, 2014 07:54 AM|nitinsomal|LINK
How can we make DataMember optional in WCF
Aug 04, 2014 10:58 AM|Siva Krishna Macha|LINK
Yes basically there are two properties for DataMember attribute with which we can control whether it needs to be serialized or not.
These are :
[DataMember(Name = "YourMember", Order = 1, IsRequired=false, EmitDefaultValue=false)]
Also use IsRequired=false, if you just need optional behaviour.
If you want the tag shouldn't be present in the response/request during the (de-)serialization process, then you may further go and use EmitDefaultValue=false. However using EmitDefaultValue is not recommended in general, unless necessary. Read this article: