views:

153

answers:

1

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

My DataContract class returns an Enum type to the consumer from one of it's exposed methods.

The consumer is able to see the enum type, and instantiate variables of that typel.

However, I have not provided a [DataContract] nor [EnumMember]s for the enum in the service.

My question is, why is the client still able to see it?? I thought that I would have had to make it a [DataContract] for it to be serialized along with the business object, no?

A: 

Yes - you had to - up to .NET 3.5 SP1.

Microsoft "loosened" the rules and now the DataContractSerializer will behave like the XmlSerializer, if you don't put any [DataContract] and [DataMember] attributes on anything: it will just simply serialize all public properties and necessary types.

While this might be a "simpler" approach for the simple scenario, you also loose lots of control over namespace, ordering etc. - so I prefer to still apply those attributes explicitly, just to clearly express (and document!) my intent. But with .NET 3.5 SP1, it's no longer required and enforced by the DataContractSerializer.

marc_s
Thanks marc, that has clarified it.
NotNowJohn