recently had a long and interesting e-mail discussion on the merits of sharing DataContract types between clients and servers in WCF (or ASMX for that matter).
Opinion was fairly divided with some thinking this is plain wrong and others thinking it is absolutely the right way to go provided you follow some basic principles to ensure that the "Share contract not class" tenet of SOA would be upheld.
I used to be a huge fan of sharing types between the client and the service in my ASMX coding days because the generated types were ugly and cumbersome to use (arrays instead of collections, incorrectly cased classes and members etc). However, this argument has lost some of its weight with the introducion of WCF and the svcutil.exe tool which allows you to specify the type to be used for collections and dictionaries.
In fact this functionality is now surfaced inside the new Add Service Reference dialog and its Advanced Settings dialog in Visual Studio 2008 which is especially neat:
Therefore I'm more or less on the fence with regards to this argument now and can see merit in both sides. For example, one significant advantage to sharing types is to reuse validation logic (such as that supported by the Validation Application Block
from P&P) between the client and the server and only having to manage and maintain this in one place.
However, of particular note is the "Reuse types in referenced assemblies" setting in Visual Studio 2008. Now, if you add a service reference to a project and this project already references the appropriate DataContracts in another
assembly it will reuse those types instead of generating new ones, and this is the default behaviour.
Whatever your view on the Sharing Types argument - it just got a whole lot easier!
The new features for WCF in Visual Studio 2008 are covered in the February edition of MSDN magazine so watch this space for the online version: http://msdn.microsoft.com/msdnmag
10 Jan 2008
» Next Post:
New in WPF 3.5: 1. Neater syntax for core Validation Rules
« Previous Post:
10 Reasons: Source Code
Comments are closed for this post.