DataContract and DataMember Attributes - How They Affect Type

what's the difference between a class without DataContract attributes:

public class BankOperationResult { public int CurrentAmount { get; set; } public bool Success { get; set; } } 

same class with DataContract attributes:

 [DataContract] public class BankOperationResult { [DataMember] public int CurrentAmount { get; set; } [DataMember] public bool Success { get; set; } } 

I mean, WCF handles these two types differently when coding, etc.

With or without these attributes, my WCF service works ...

Thanks Pawel

+6
wcf datacontract
source share
1 answer

Prior to .NET 3.5 SP1, if you did not mark your property with the DataMember attribute, it was not shown in WSDL and was not serialized. Starting with .NET 3.5 SP1, the DataContractSerializer will automatically include all public properties, so you no longer need to decorate them with this attribute.

+10
source share

All Articles