Why to keep WCF Implementation and ServiceHost separately?

502 views Asked by At

What is the benefit to keep the WCF project having - WEB HOST PROJECT and Service Implementaiton project separately.

  1. Service contract library
  2. Service implementation library
  3. Service Host project

I understand Contract and Implementaiton to keep separate will helpful for SOC principal and allow to use into other application also if require to implement interfaces.

But,I am not understand why to keep - Service Host and Service Implmentation project separately.

I went through below link, but not understand the benefit of keeping this separate. http://www.devx.com/codemag/Article/39837 (Page 4,5)

If any one guide here then, it is helpful.

Thank You

2

There are 2 answers

2
AudioBubble On

As the article said:

Decoupling the services from the host lets you host your services in whatever type of host you want, and to change that host any time. Now, the host could be an IIS application, Windows Activation Services, or any self-hosting application including console applications, Windows Forms applications, Windows Services, etc. - WCF the Manual Way…the Right Way : Page 3

Test mocking, though important, arguably applies to most things programming wise. What is more useful here however is how service separation helps to deploy said services in production, not how it helps developer-level testing. The latter is only useful for a short time period compared to the operational life of the system in production where operations staff may change how the service is hosted. Operations, from an ALM perspective, continues way after SDLC completes.

Though off topic here, one can go further and decouple service logic itself not only from the service's contract but also from anything WCF-related. As mentioned in Thomas Erl's book SOA Design Patterns -

Facade logic is placed in between the contract and the core service logic. This allows the core service logic to remain decoupled from the contract. - Service Façade

  • Keeping the WCF implementation and WCF host process separate allows you to change how it is hosted later
  • Advanced: Keeping the WCF implementation and service processing logic separate ensures the latter is free to change without impacting users of the exposed service contract
0
ZZZ On

In addition to Micky's answer, I give you some examples of deployment. 1. If you are going to host the service in IIS, you don't need the Service Host project, since IIS/WAS/.NET runtime will created a service host for you upon the first client request. 2. If you want to host the service in Windows service or a console app, you may create the service host in the Window service project or the console application project, because there will be just a few lines of codes for creating Service Host, unless you have complex logic of managing service host.