简体   繁体   English

在WCF服务中在运行时公开类的一些属性

[英]Expose few property of class at runtime in WCF service

I have a class for ex User class in WCF service, In that i have 10 properties like Fname, Lname, ServiceStatus, ErrorMessage etc. 我在WCF服务中为ex User类提供了一个类,其中有10个属性,如Fname,Lname,ServiceStatus,ErrorMessage等。

Now there is method in service who retrieve the user info by giving the valid Json input and gives output in Json format (Here I am exposing user class object). 现在有一个服务中的方法,该方法通过提供有效的Json输入并以Json格式提供输出来检索用户信息(这里我公开了用户类对象)。

Now my problem: - Now when i expose this user class then i got the all properties in json output. 现在我的问题:-现在,当我公开此用户类时,我在json输出中获得了所有属性。 There were few cases where i don't want to expose all properties. 在少数情况下,我不想公开所有属性。 In some cases I want to expose only two properties, or in few cases all properties. 在某些情况下,我只想公开两个属性,或者在少数情况下,只公开所有属性。 I want to do this to make JSON Output more clear. 我想这样做以使JSON输出更加清晰。

Is it Possible in WCF? 在WCF中可能吗? Please help. 请帮忙。

不要将[DataMember ]属性放置或不向您不想公开的属性添加[IgnoreDataMember]属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM