Suppose i have a service, where i give some input , and i am setting the properties of Name and Age as Nothing Name and Age are nullable types. Now as Name and Age are nothing i do not want a xml tag generated in the output.Bu开发者_运维问答t below xml tags are generated with nil=true.
<Name xsi:nil="true"/>
<Age xsi:nil="true"/>
You can control the way WCF serialize objects. Take a look here here
Set the IsRequired
and EmitDefaultValue
properties of the DataContract
attribute to false:
[DataMember(IsRequired = false, EmitDefaultValue = false)]
public string Name { get; set; }
[DataMember(IsRequired = false, EmitDefaultValue = false)]
public byte? Age { get; set; }
精彩评论