开发者

How to remove null DataMember properties from the response in wcf

I am returning the 开发者_运维技巧xml output to the browser with a wcf webservice, if a property of a DataContract is null, it still comes through in the response as

<Id i:nil="true" />

Is there a way to have it not return in the response at all?


Figured it out myself, I needed to add the following atrribute to my DataMembers

[DataMember(EmitDefaultValue = false)]


In the class in which your property is present have a constructor. In the constructor initialize it as null. If a property of a DataContract is null, then it will not appear in your xml output. If you want it to appear it in your output when data is present in it just instantiate it again in your class where you expose the data.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜