Download Code - 174.4 KB
Few words about WCF
WCF is unified communication platform from Microsoft and most preferred choice for SOA
development like earlier we have asmx webservice. WCF provide all the powerful
cross platform communication needs and flexibility of hosting in IIS,Windows
applications, Console applications, Windows service,MSMQ and various protocols support
(like http, named pipes,TCP etc.)and bindings.
The problem area
In Visual studio, WCF service development is as easy as asmx webservice, but
service,endpoint (.svc file) contract and configuration all jumbled in one
project. And we have to maintain a large web.config file. Most of the WCF
hosting and binding configurations are reside inside service configuration file.
Traditionally we need to create proxy in each and every project to consume the
WCF service, so if we need to consume WCF service in multiple project projects ,
than need to create same proxy class in different projects. It’s is code
duplication. And if there is any change in the WCF service, we need to change
the config file and proxy for each and every project.
If we have one proxy for all projects,separate out contract and service and maintain configuration on the hosting
environment instead of within service, would be more suitable for large
enterprise systems as it would be up to the host how WCF service would be
exposed (configuration at the host point not at service side). I have developed
a sample that decoupled service, contract, host and proxy from the client.
I have created 5 diffeent projects each one for Contract,service,Host,proxy and
Contracts and Service projects are class libraries and doesn't have any
WCF Proxy is again a class library and client is a windows application, both proxy and client is having the almost the same config entry.
Service is exposing two simple methods GetPrice and GetProductName.
Here the proxy class is derived from the ClientBase