|
||||||||||
So if you don't use the built-in templates to create your services, what do you use? Well keep reading and I'll show you how to create everything you need manually with ease while maintaining good design and coding practices. WCF is probably one of the absolutely coolest technologies to come out of Microsoft. I think the unified model toward developing message-based applications and service-oriented applications is long overdue in our industry, and I'm glad to see that it came from Microsoft. That said, I'm not too crazy about the templates that come with Visual Studio 2008 or the 3.0 extensions for Visual Studio 2005. I feel Microsoft could have done a better job with code separation and the enforcement of good practices—never mind best practices. Another area where I see developers doing things automatically and falling a bit short is in referencing services from client application. When developers used mainly web services, the choices were limited, but such is no longer the case. Adding service references automatically may not be the best way to write service consumers. Fortunately you can easily solve these problems by creating all your service components manually; it's not even that hard to do. This article assumes you have some basic knowledge of WCF services and the elements that comprise them; not too much, just a bit. The Problem with WCF Templates I love getting into political conversations, and one of my pet peeves is when politicians criticize and destroy current policy without offering a better solution for how things should be done. I won't fall into that trap; instead, I'll tell you exactly what I feel is wrong with the WCF-related project and item templates that come with Visual Studio, and then I'll tell you how I think you can overcome these problems. The current WCF templates in Visual Studio as well as the "Add Service Reference" tool suffer from one major problem: they do too much. Developers would have benefited a lot more from having more templates that do less. When you add a service, Visual Studio automatically creates both the contract and the service in your project—two things that should be in separate projects (for reasons I will explain later). Creating service web projects not only creates these two items but also the service host—which again, I feel should be in its own assembly. Both situations also add to the configuration file. While this is good for educational purposes, it can also clutter up an existing clean configuration file. Instead, Visual Studio should include templates for individually creating all these elements. In addition, I'd like to see a project template to create a self-host project that's not IIS-based. The Add Service Reference tool creates too much for you, and does not promote good code reuse. Not only does it create proxies for you, but it adds an immense amount of configuration information. To illustrate what I mean, I'll walk you through a project using the WCF templates and tools to develop a simple service and client. Then I'll analyze what's wrong with the results and provide alternatives.
|
||||||||||
|