tags:

views:

26

answers:

1

I have several classes such as Order, Customer, etc. These classes serve for holding data and nothing more. I want to be able to reuse these classes in other projects in the future, but for some reason I don't quite understand, WCF forces me to decorate the data members with the [DataMember] attribute, forcing me to reference WCF plumbing that I will never use in other projects.

I would imagine that WCF lets you take any serializable class and use it as a content type. Am I understanding this correctly?

+1  A: 

Yes, with .NET 3.5 SP1, the WCF DataContractSerializer will now serialize any POCO class just the same way as the XmlSerializer will - any public property will be serialized.

I don't know for sure whether that's a good thing - one of the pillars of WCF is being explicit, in order to clearly state your intent. I personally find it a good thing to mark your classes with [DataContract] and your fields and properties you want to have serialized explicitly with [DataMember] - it makes it clearer as to what's going on, and it doesn't hurt your POCO class at all.

And btw: you don't have to reference any "WCF plumbing" to do this - those attributes live in System.Runtime.Serialization - a very generic system assembly.....

marc_s
Thanks! Boy, I need to snap out of the old school way thinking. I am always weary of any situation where I have to add code. In this particular case, I feared that the extra decoration would just add code for the sake of WCF. As you have demonstrated, the extra code is useful for other .NET technologies.The .NET folks really thought hard about design. Everything in .NET seems to snap together nicely. It lets you have your cake and eat it too. I often walk away from the code and marvel at how understandable and pretty it is! .NET is looking like the holy grail of software development.
Joel Rodgers