views:

285

answers:

4

What are the various methods of hosting a WCF service?

+2  A: 

There are four common ways, all of which are outlined nicely on MSDN: Hosting WCF Services.

  1. Hosting in IIS.
  2. Hosting in WAS.
  3. Hosting in a Windows service.
  4. Hosting in an application (aka "self-hosting").
bobbymcr
Hosting in a Windows service and hosting in an application is essentially the same thing, as a Windows service is just another application.
Mark Seemann
Sure, but they have enough different considerations that they are explicitly called out separately in MSDN. Really, my answer is arranged exactly as MSDN lays it out. :)
bobbymcr
noteworthy that an application can also be a forms app
Marc Wittke
A: 

You can host it in an IIS application or in your own executable. Typically the executable would be a windows service application.

Matt Wrock
I wouldn't necessarily say that the 'typical' case for hosting a WCF service within an executable is via a Windows service. WCF services provide an alternative to .NET Remoting for communicating across AppDomain boundaries. As such, WCF is just as likely to be used within a Windows Forms application as it is a Windows service.
Matt Davis
While you could certainly host a WCF service in a winforms app, I'm not sure many apps would do this. I think winforms apps would most likely be a WCF consumer and not necessarily a host. But then maybe I'm being short sighted and not envisioning a class of use casses that you have in mind.
Matt Wrock
As an example, if an application is extensible via plug-ins, it makes sense to load these plug-ins in their own AppDomain. Once that is done, the application is now faced with the issue of bridging the AppDomain divide for communication purposes, a problem that WCF easily solves (as can .NET Remoting and inheriting from MarshalByRefObject). I think in many cases, your assertion is correct; I just don't know that I go as far as saying it's 'typical'. Sorry to quibble. :)
Matt Davis
A: 

Any Windows process can be used to host a WCF service. There are practically no restrictions on this - a process can host multiple WCF services and the same WCF service type can be hosted across multiple processes simultaneously.

From Juval Lowy's book Programming WCF Services, hosting can be provided by

  • Microsoft Internet Information Server (IIS)
  • Self-hosting within a Windows Forms application, Windows service, or console app
  • Windows Activation Service (WAS)
Matt Davis
A: 

For right now, everything that's been said is correct.

  • Hosting in IIS6 only support HTTP protocols and "on-demand" activation
  • Hosting in IIS7 / WAS (only on Vista / Server 2008 and up) supports all protocols and "on-demand" activation
  • Self-Hosting in a console app or Windows service supports all protocols, but doesn't support on-demand activation (e.g. your service must be up and running all the time, it cannot be magically activated when a request comes in)

What's not been mentioned is what the .NET 4.0 wave later this year (2009) will offer - there's a new add-on server component called Dublin which is said to offer a rich and managed hosting environment for both WCF services as well as WF workflows.

Marc

marc_s