如何从WCF响应删除空DataMember属性属性、WCF、DataMember

2023-09-03 00:49:52 作者:看清了也就看轻了

我返回的XML输出​​到浏览器与WCF web服务,如果DataContract的属性为空,但仍来自通过在响应为

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?

推荐答案

想通了我自己,我需要以下atrribute添加到我的数据成员

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

[DataMember(EmitDefaultValue = false)]