开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜