Tuesday, July 17, 2007

WCF: Sharing Types between Server and Client

A discussion I've run into time and time again through the last few months when I've been working with WCF is whether to use the generated proxy classes client-side or think of something else (like inherting the proxy-classes, creating your own proxies, or somehow try to make the proxy classes identical to the source classes).
I guess the discussions arise as a result of people not being sure if they should consider WCF like Web Services which has a loose coupling (generated client proxies) or like Remoting which often has a tighter coupling between the interacting participants (shared dll).
Until now I've mainly been a fan of the loose coupling because of three things:
  • It's the easiest and fastest just click the right buttons in your VS and you're set! (yes, I can be quite lazy at times but remember that lazy developers often are the best)
  • There's no dependency of a specific version dll between the client and the server. If the Server gets an update that breaks the service-convention the client just has to regenerate it's proxy and you're set.
  • I havn't seen a clean and pretty alternate solution before. Mostly it's been messy.
However today I just came across this excellent codeproject posting that gives a fine example of how to share a type between a WCF Service and a WCF consumer. It turns out that it's built into the SvcUtil (the client proxy generator) as a command-line switch. Now doesn't that make me feel stupid :-)

No comments: