I am trying to figure out the lifetime of a WebServiceHost. I thought that it would initially be per-call/per-request (i.e. Similar to an ASP.Net page being created for each request). I've created a Custom WebServiceHostFactory and WebServiceHost, but noticed that the Factory and Host are only created once.
The CustomWebServiceHostFactory overrides CreateServiceHost and the CustomWebServiceHost overrides OnOpening to spit out some diagnostics to track lifetimes.
My Service File
[ServiceContract]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public partial class ProductService
{
... // code
}
My Global.asax File
private void RegisterRoutes()
{
RouteTable.Routes.Add(new ServiceRoute("products", new CustomServiceHostFactory(), typeof(ProductService)));
}
Is anyone able to explain why two requests are hitting the same instance of CustomWebServiceHost, and how I would create a new Host for each service request?
Thanks