我有一個WCF客戶端服務在IIS 7下託管並使用Autofac的WCF集成。此服務由另一個WCF服務調用,使用基本Http綁定。自從3個月前開始使用該服務以來,一切工作都已開始以及。Autofac WcfIntegration - 通過net.tcp進行通信時無法激活WCF客戶端服務
然而,當我嘗試調用過的net.tcp這項服務,我能做到這一點,接收回調一段時間(通常約8小時)後,我不斷收到此錯誤:
從託管服務器The requested service, 'net.tcp://ecomsvc.webhost.com:12345/EcomSvc.svc' could not be activated.
的例外是:
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.
服務的標記:
<%@ ServiceHost Service="EcomService.Contract.IEcomSvc, EcomService.Contract" Factory="Autofac.Integration.Wcf.AutofacHostFactory, Autofac.Integration.Wcf" %>
Autofac登記:
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;
}
WCF服務從上面Autofac註冊調用客戶端:
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();
}
標記:
<%@ ServiceHost
Service="HandlerService.IHandlerSvc, HandlerService"
Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, Autofac.Integration.Wcf" %>