[英]How do I configure autofac with WCF under Azure with a WebRole
我正在尝试为Azure配置一个简单项目,以使用带有Http绑定的WCF服务,并使用Autofac的WCF集成。 目前,我正在本地测试并在IIS(Azure)下托管。
首先,我将项目设置为在没有Autofac的情况下运行,并且可以实例化服务并查看通过浏览器公开的WSDL端点。
然后,我修改了service svc文件并添加了Factory定义。
<%@ ServiceHost Language="C#" Debug="true" Service="EposDataService" Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, Autofac.Integration.Wcf" %>
接下来,我修改了WebRole类:
public override void Run()
{
// This is a sample worker implementation. Replace with your logic.
Trace.WriteLine("Worker entry point called", "Information");
var builder = new ContainerBuilder();
builder.RegisterModule(new ServiceModule());
//using (m_Container = builder.Build())
m_Container = builder.Build();
//{
AutofacHostFactory.Container = m_Container;
while (true)
{
// sleep 30 minutes. we don't really need to do anything here.
Thread.Sleep(1800000);
Trace.WriteLine("Working", "Information");
}
//}
}
但是,当我在本地部署服务并尝试访问该服务时,出现错误:
The AutofacServiceHost.Container static property must be set before services can be instantiated.
Exception Details: System.InvalidOperationException: The AutofacServiceHost.Container static property must be set before services can be instantiated.
我不了解的是,静态属性是在WebRole中设置的,但看起来好像是在重置分配。 有什么建议么?
答案似乎是多种因素共同作用的结果。
首先,我将Autofac注册和增强功能从WebRole移到了Global.asax。 这有助于解决我最初收到的错误消息。
其次,我更正了服务注册中的一个错误,并从以下位置重新配置了注册:
builder.RegisterType<EposDataService>().As<IEposDataService>()
至
builder.RegisterType<EposDataService>().AsSelf();
参考: -autofac wcf注册错误
第三,我在svc中完全限定了服务名称。 参考文献:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.