0

I am trying to configure a simple project for Azure to use a WCF service with Http bindings, and using Autofac's WCF integration. Currently I am testing locally and hosting under IIS (Azure).

First I set up the project to run without Autofac and can instantiate the service and see the WSDL endpoint exposed through a browser.

I then modified the services svc file and added a Factory definition.

<%@ ServiceHost Language="C#" Debug="true" Service="EposDataService" Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, Autofac.Integration.Wcf" %>

I next modified the WebRole class:

 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");
            }
        //}    
    }

However when I deploy the service locally and try and access the service, I get an error:

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.

What I don't understand is that the static property is being set in the WebRole but it appears as if something is resetting the assignment. Any suggestions?

kiwisurfer
  • 11
  • 2
  • The only thing that makes sense is that the AutofacServiceHost type is being initialised in one AppDomain, but the services are running in another. – kiwisurfer Mar 09 '13 at 21:59
  • This link seems to imply that this is the case. http://blogs.msdn.com/b/windowsazure/archive/2010/12/02/new-full-iis-capabilities-differences-from-hosted-web-core.aspx – kiwisurfer Mar 09 '13 at 22:00

1 Answers1

1

The answer appears to be a combination of factors.

First, I moved the Autofac registration and boostrapping from WebRole to Global.asax. This is what helped address the error message I first received.

Secondly I corrected a mistake in my service registration and I reconfigured the registration from:

builder.RegisterType<EposDataService>().As<IEposDataService>()

to

builder.RegisterType<EposDataService>().AsSelf();

Reference: - autofac wcf registration error

Thirdly I qualified the service name in the svc fully. References:

Community
  • 1
  • 1
kiwisurfer
  • 11
  • 2