Enumerations, DataContracts, and WCF

I am new to WCF and have a simple question ...

My DataContract class returns an Enum type to the user from one of the public methods.

The consumer can see the enumeration type and create variables of that type.

However, I have not provided an enumeration of [DataContract] and [EnumMember] in the service for enumeration.

My question is, why is the client still able to see it? I thought I would have to do this [DataContract] to serialize it along with the business object, no?

+2


a source to share


2 answers


Yes - you needed before .NET 3.5 SP1.

Microsoft has "relaxed" the rules, and DataContractSerializer

will now behave as XmlSerializer

if you do not put any attributes [DataContract]

and [DataMember]

on anything: it will just serialize all public properties and required types.



While this might be a "simpler" approach for a simple scenario, you also lose a lot of control over namespace, ordering, etc. - so I prefer to use these attributes explicitly to clearly express (and document!) my intent. But with .NET 3.5 SP1, it is no longer required and is no longer implemented with DataContractSerializer

.

+1


a source


if we don't put any [DataContract] and [DataMember] attributes on everything, that will automatically serialize all public properties and required types. This feature is supported from the higher version of .NET3.5 SP1.



0


a source







All Articles