In all the host programs of WCF services we need to write the something like:
using(ServiceHost host = new ServiceHost(typeof(<ServiceType>)))
The class System.ServiceModel.ServiceHost provides the functionality to host Windows
Communication Foundation (WCF) services.This is a derived class
of ServiceHostBase and is used to load a service, configure endpoints, apply security
settings, and start listeners to handle incoming requests.The ServiceHost class creates a
ServiceDescription from the service type and configuration information and then uses
that description to create ChannelDispatcher objects for each endpoint in the description.
But while developing the IIS hosted services we need not write code for the host at all.
So how does the hosting functionalities mentioned above is taken care
when we are hosting the service in IIS?
For a WCF Service hosted in IIS we have the following flow:
1.The messages are directed to System.ServiceModel.Activation.HttpHandler
by the aspnet_isapi.dll
2.The HttpHandler depends upon the System.ServiceModel.Activation.WebServiceHostFactory
to create an instance of service host.The CreateServiceHost method of WebServiceHostFactory
creates an instance of WebserviceHost.
System.ServiceModel.Web.WebServiceHost class is derived from ServiceHost class.This class provides
extended ServiceHost functionality for IIS Hosted Services.If there are no endpoints configured then
it automatically creates a default endpoint at the service’s base address for HTTP and HTTPS base
addresses. It does not create an endpoint automatically if the user has configured an endpoint
explicitly at the base address. WebServiceHost automatically configures the endpoint’s binding to
work with the associated Internet Information Services (IIS) security settings when used in a
secure virtual directory.WebServiceHost class also adds the WebHttpBehavior to all endpoints
that does not have the behavior.