[英]Ignore some properties when transfering an object from the WCF service to the client
I have a poco on the service side of my application. 我的应用程序的服务端有问题。 I want to transfer this object to the client but WITHOUT some specific properties.
我想将此对象传输到客户端,但没有一些特定的属性。
Is there a way to "hide" some properties when returning the result to my client? 返回结果给我的客户时,是否有一种“隐藏”某些属性的方法?
I already tried [IgnoreDataMember] , [IgnoreProperties("xxx")] , [NonSerialized] and many other attributes without luck... Is there any way to do this? 我已经尝试过[IgnoreDataMember],[IgnoreProperties(“ xxx”)],[NonSerialized]和许多其他属性,但是没有运气。有什么办法可以做到这一点?
Your WCF service must be using a DataContract
on the poco class, remove [DataMember]
attribute from the properties and that should work. 您的WCF服务必须在poco类上使用
DataContract
,从属性中删除[DataMember]
属性,并且该属性应该起作用。
For example, below BoolValue
will not be part of the contract. 例如,以下
BoolValue
将不属于合同的一部分。
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";
//Not a part of contract
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.