Hosting WCF: IIS or Windows service
I have been asked many times by customers how to choose a WCF host. IIS or self host?
(A self host is usually implemented as a windows service)
So first we have to understand that we are in the Http world because IIS is not playing in the game of other transports (excluding SMTP).
IIS has a very special life model. IIS was designed for hosting many stateless applications.
If an application hosted by IIS is not called for x minutes (20 by default) it will be recycled.
Resource recycling is important when you host many applications but If your application holds state this can be quite sad to loose the information after 20 min.
IIS7.0 was designed to host many applications simultaneously. Every such application is hosted in a separate application domain. Each application domain has its own configuration and thread pool.
IIS act as a central management point for all those applications.
It is not easy to build a host that puts all the services it hosts in separate application domains but on the other hand can continue to configure them. Remember that application domain has a clear isolation from each other (like process separation in windows)
IIS has a simple but effective security model. It is easily configured and is consistent with other web applications.
IIS has a strong configuration infrastructure. It uses a tree of configuration files. Machine.config and web.config. Each file adds or overrides configuration to the layer above. WCF has no such thing.
IIS can be configured using an advanced API.
All this is not easy to build.
IIS 7.0 is extremely extensible. You can add handlers and modules and change the pipeline.
It is not easy to create such a host yourself.
IIS is a deployment requirement that is sometimes not to easy to forefeel. In server scenarios usually it is not a problem but if you want a little application to be a WCF server, IIS is a no-go. Let us say you want your smart client to listen for answers another server will send (one-way messaging) this smart client should contain a ServiceHost. Now you are very happy not to use IIS. There are many other scenarios where you want a simple and clean install. You want as little pre-requisites as possible. Create your own simple host can be the solution for you.
IIS supports WMI and other advanced Governance tools. It is not easy to build a host that can be governed from a central remote station. WCF does support for WMI and performance counters so this can be a starting point when you create your host, but there is no question that IIS has a lot more to offer in the governance arena.
To summarize:
Write down the capabilities you need. Then look what does IIS has to offer. A good host takes a lot of time to develop and test but there are many scenarios that this is what you need.
Manu