michelqa
michelqa

Reputation: 157

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?

Upvotes: 0

Views: 857

Answers (1)

Habib
Habib

Reputation: 223237

Your WCF service must be using a DataContract on the poco class, remove [DataMember] attribute from the properties and that should work.

For example, below BoolValue will not be part of the contract.

[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; }
    }
}

Upvotes: 1

Related Questions