The ServiceHost used to host the service is a point of extensibility within the Windows Communication Foundation (WCF) programming model. A factory pattern is used to instantiate the ServiceHost because it is, potentially, a polymorphic type that the hosting environment should not instantiate directly.
The default implementation uses ServiceHostFactory to create an instance of ServiceHost. But you can provide your own factory (one that returns your derived host) by specifying the CLR type name of your factory implementation in the @ServiceHost directive.
To use you own custom service host factory instead of the default factory, just provide the type name in the @ServiceHost directive as follows:
<% @ServiceHost Factory=”DerivedFactory” Service=”MyService” %>
Keep the factory implementations as light as possible. If you have lots of custom logic, your code is more reusable if you put that logic inside your host instead of inside the factory.
For example, to enable an AJAX-enabled endpoint for MyService, specify the WebScriptServiceHostFactory for the value of the Factory attribute, instead of the default ServiceHostFactory, in the @ServiceHost directive as shown in the following example.