0
我正在嘗試爲Azure配置一個簡單的項目,以便使用帶有Http綁定的WCF服務並使用Autofac的WCF集成。目前我正在本地測試並在IIS(Azure)下託管。如何使用WebRole在Azure下使用WCF配置autofac
首先,我將項目設置爲在沒有Autofac的情況下運行,並可以實例化服務並查看通過瀏覽器公開的WSDL端點。
然後我修改了服務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中設置的,但它看起來好像有什麼東西在重新設置分配。有什麼建議麼?
有意義的是,AutofacServiceHost類型正在初始化一個AppDomain中,但服務是在另一個運行的唯一的事。 – kiwisurfer 2013-03-09 21:59:48
這個鏈接似乎意味着這是事實。 http://blogs.msdn.com/b/windowsazure/archive/2010/12/02/new-full-iis-capabilities-differences-from-hosted-web-core.aspx – kiwisurfer 2013-03-09 22:00:55