What is the difference between hosting WCF service on IIS, Windows Service and self-hosted app?

Technology CommunityCategory: WCFWhat is the difference between hosting WCF service on IIS, Windows Service and self-hosted app?
VietMX Staff asked 3 years ago

There is no standard answer to this question. IIS provides you with a lot of out-of-the-box features, like app domain reloading, monitoring and so on. This is why you should answer this questions first: do you need all these features or not? If not – windows service can be considered.

Other thing to consider:

  • IIS gives you on-demand loading – this can be a plus or a minus. When a request comes in, the ServiceHost is constructed, then the service class being hosted is instantiated, and the request is handled. Nothing needs to be running around the clock. But at the same time, this setup requires more time and effort every time a message comes in, and you as a programmer don’t have much control over your service host, really.
  • Self-hosting is often times faster, since your ServiceHost is already up and running – but it’s up to you to make sure it really is up and running, there’s no “on-demand” loading whenever a message comes in – either it’s up and can service the request, or not. But you have a lot more control over the service host – when and how it’s constructed etc., and you get to pick and define your service addresses as you see fit.

And some information from Microsoft:

Hosting Environment Common Scenarios Key Benefits and Limitations
Managed Application (“Self-Hosted”) – Console applications used during development. – Rich WinForm and WPF client applications accessing services. – Flexible.- Easy to deploy.- Not an enterprise solution for services.
Windows Services (formerly known as NT services) – A long-running WCF service hosted outside of IIS. – Service process lifetime controlled by the operating system, not message-activated.- Supported by all versions of Windows.- Secure environment.
IIS 5.1, IIS 6.0 – Running a WCF service side-by-side with ASP.NET content on the Internet using the HTTP protocol. – Process recycling.- Idle shutdown.- Process health monitoring.- Message-based activation.- HTTP only.
Windows Process Activation Service (WAS) – Running a WCF service without installing IIS on the Internet using various transport protocols. – IIS is not required.- Process recycling.- Idle shutdown.- Process health monitoring.- Message-based activation.- Works with HTTP, TCP, named pipes, and MSMQ.
IIS 7.0 – Running a WCF service with ASP.NET content.- Running a WCF service on the Internet using various transport protocols. – WAS benefits.- Integrated with ASP.NET and IIS content.