Only send properties of populated objects over WCF?

I have an object that is dispatched through WCF, which is essentially the owner of the property - it can potentially have a large number of properties, that is, up to 100, but in general only a small subset will be set, up to 10 for the 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 send only completed properties on the wiring? It looks like a potential waste of bandwidth for sending across the entire facility.

+3
source share
1 answer

Yes, you can do this:

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

        ........    

        /* repeat another X times */
}

Learn more about validating the EmitDefaultValue MSDN property

+4
source

Source: https://habr.com/ru/post/1745202/


All Articles