I have a WCF client service hosted under IIS 7 and using Autofac's WCF Integration. This service is called by another WCF service, using basic Http Bindings. Everything has worked well since the service started being used, about 3 months ago.
However, when I try calling this service over net.tcp, I am able to do it and receive callbacks for a period of time (about 8 hours usually) after that I keep receiving this error:
The requested service, 'net.tcp://ecomsvc.webhost.com:12345/EcomSvc.svc' could not be activated.
Exception from the hosting server is:
Exception: System.ServiceModel.ServiceActivationException: The service '/EcomSvc.svc' cannot be activated due to an exception during compilation. The exception message is: The AutofacServiceHost.Container static property must be set before services can be instantiated.. ---> System.InvalidOperationException: The AutofacServiceHost.Container static property must be set before services can be instantiated.
Service's markup:
<%@ ServiceHost
Service="EcomService.Contract.IEcomSvc, EcomService.Contract"
Factory="Autofac.Integration.Wcf.AutofacHostFactory, Autofac.Integration.Wcf" %>
Autofac registration:
private static void SetupDependencyContainer()
{
var builder = new ContainerBuilder();
// Register service implementations.
builder.RegisterType<EcomSvc>().As<IEcomSvc>();
// Set the dependency resolver.
var container = builder.Build();
AutofacHostFactory.Container = container;
}
The WCF service calling the client from above Autofac registration:
private static void SetupDiContainer()
{
var builder = new ContainerBuilder();
// Register service implementations
builder.RegisterType<HandlerSvc>().As<IHandlerSvc>();
builder.RegisterType<HandlerService().InstancePerLifetimeScope();
ConfigureServices(builder);
//register other dependencies
builder.RegisterType<ProxyCache>().As<IProxyCache>().InstancePerLifetimeScope();
// Set the dependency resolver.
var container = builder.Build();
AutofacHostFactory.Container = container;
}
private static void ConfigureServices(ContainerBuilder builder)
{
RegisterService<IEcomSvc>(builder, "EcomServiceTCP");
}
public static void RegisterService<T>(ContainerBuilder builder, string endpoint)
{
builder.Register(c => new ChannelFactory<T>(endpoint))
.SingleInstance();
builder.Register(c => c.Resolve<ChannelFactory<T>>().CreateChannel())
.As<T>().UseWcfSafeRelease();
}
Markup:
<%@ ServiceHost
Service="HandlerService.IHandlerSvc, HandlerService"
Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, Autofac.Integration.Wcf" %>