What's the point of a DataContract in WCF?

前端 未结 6 1635
情歌与酒
情歌与酒 2020-12-07 14:07

VS.net creates a template when you create a WCF project.

It adds a class to the iService1.cs file:

// Use a data contract as illustrated in the sampl         


        
6条回答
  •  清歌不尽
    2020-12-07 14:38

    Perhaps not often used, we could use [DataContract] to pass through private variables. The DataContractSerializer will serialize/deserialize only publicly visible types if [DataContract] attribute is not used.

    [DataContract]
    public class SampleClass
    {    
        [DataMember]
        private int MyPrivateProperty { get; set; }
    }
    

    (Note: If you are generating a proxy then private members are exposed as public)

提交回复
热议问题