我正在尝试为 Azure 配置一个简单的项目,以使用带有 Http 绑定的 WCF 服务,并使用 Autofac 的 WCF 集成。目前我正在本地测试并在 IIS (Azure) 下托管。
首先,我将项目设置为在没有 Autofac 的情况下运行,并且可以实例化服务并查看通过浏览器公开的 WSDL 端点。
然后我修改了服务 svc 文件并添加了工厂定义。
<%@ 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 中设置的,但看起来好像有什么东西正在重置分配。有什么建议么?