如何从WCF响应删除空DataMember属性 [英] How to remove null DataMember properties from the response in wcf

查看:102
本文介绍了如何从WCF响应删除空DataMember属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我返回的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)]

这篇关于如何从WCF响应删除空DataMember属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆