开发者

How to avoid creation of xml tag for properties which has the value Nothing in WCF?

开发者 https://www.devze.com 2022-12-10 20:42 出处:网络
Suppose i have a service, where i give some input , and i am setting the properties of Name and Age as Nothing

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

精彩评论

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

关注公众号