Friday, September 23, 2011

Check required fields in de-serialization of WCF objects

You can set IsRequired = True and EmitDefaultValue = False.

This will tell Wcf runtime to serialize data member but do not serialize default values, i.e. do not serialize null values for reference types, 0 for integers, etc.In effect, a runtime exception will be thrown if the data member has not been assign a value during serialization. If we do not set EmitDefaultValue toFalse CLR will set it to zero (default for integer) automatically.