通过 Web 服务公开时隐藏公共属性 [英] Hide public Property when exposed through web service

查看:31
本文介绍了通过 Web 服务公开时隐藏公共属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想防止属性通过我的 WCF Web 服务公开.我尝试添加无效的 XmlIgnore 属性错误.我们正在使用 .NET 3.5.周转基金.

I would like to prevent a property from being exposed via my WCF web service. I tried adding the XmlIgnore attribute bug that didn't work. We are using .NET 3.5. WCF.

这不起作用:

    public class MyClass
    {
        public string S1 { get; set; }

        [XmlIgnore]
        public string S2NotExposed { get; set; }
    }

推荐答案

使用 DataContractAttribute Class ,然后仅标记您想使用 DataMemberAttribute 类.

Mark your class with the [DataContract] attribute from the DataContractAttribute Class , then mark only the properties you want to expose with the [DataMember] attribute from the DataMemberAttribute Class.

这篇关于通过 Web 服务公开时隐藏公共属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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