tags:

views:

75

answers:

1

I have an object that is being sent across WCF that is essentially a property holder - it can potentially have a large number of properties, i.e. up to 100, but in general only a small subset will be set, up to 10 for instance.

Example:

[DataContract(Namespace = "...")]
public class Monkey
{
        [DataMember]
        public string Arms { get; set; }

        [DataMember]
        public string Legs { get; set; }

        [DataMember]
        public string Heads { get; set; }

        [DataMember]
        public string Feet { get; set; }

        [DataMember]
        public string Bodies { get; set; }

        /* repeat another X times */
}

Is there a way to tell WCF to only send the populated properties over the wire? It seems like a potential waste of bandwidth to send over the full object.

+4  A: 

Yes it is possible you can make like this

[DataContract(Namespace = "...")]
public class Monkey
{
        [DataMember(EmitDefaultValue=false, ....)]
        public string Arms { get; set; }

        ........    

        /* repeat another X times */
}

More details on EmitDefaultValue property check MSDN

Incognito