【发布时间】:2013-03-09 08:19:00
【问题描述】:
我正在尝试为 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 中设置的,但看起来好像有什么东西正在重置分配。有什么建议?
【问题讨论】:
-
唯一有意义的是 AutofacServiceHost 类型正在一个 AppDomain 中初始化,但服务正在另一个 AppDomain 中运行。
-
这个链接似乎暗示了这种情况。 blogs.msdn.com/b/windowsazure/archive/2010/12/02/…