ServiceHostBase Never Calls ApplyConfiguration

The ServiceHost class is the primary host for running services programmed using the WCF service programming model. Some of the features exposed by ServiceHost include configuration, service description, and endpoint management to control how the service operates.

A base class for ServiceHost, called ServiceHostBase, contains a portion of those exposed features and allows you to implement hosts for other service programming models. For example, we have a service host implementation for integration with COM+ services.

It's also common to derive custom hosts that support the WCF service programming model by extending ServiceHost directly rather than using ServiceHostBase and reimplementing that functionality. One example here is deriving from ServiceHost to override the ApplyConfiguration method that ordinarily would load the application configuration files to build the service description.

The ApplyConfiguration method is actually implemented on ServiceHostBase but is never called by that class. Only the derived class ServiceHost invokes the method. You might write a host using ServiceHostBase and think to override ApplyConfiguration to change the configuration loading behavior, but this has no immediate effect. If you're not using ServiceHost, then you would also need to call ApplyConfiguration yourself at some point during the initialization of your host since this is ordinarily done by ServiceHost on your behalf.

Comments (1)

  1. alexdej says:

    Really you should call InitializeDescription(), which calls both CreateDescription and ApplyConfiguration for you.

Skip to main content