I just downloaded a new version of autofac, autofac.web and autofac.integration. I am learning how to host a service in iis. I have implemented a simple service which I am able to self-host it. However, when I try to host it in IIS, I got the error"The AutofacServiceHost.Container static property must be set before services can be instantiated"I am grateful for your help. The code isnamespace WCFService
{
[ServiceContract]
public interface IMyService
{
[OperationContract]
string Hello();
}public class MyService : IMyService
{
public string Hello()
{
return "Hello WCF";
}
}
}namespace WCFService
{
public class MyServiceFactory : AutofacServiceHostFactory
{
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
var builder = new ContainerBuilder();
builder.Register(c => new ChannelFactory<IMyService>(new BasicHttpBinding(), new EndpointAddress("http://localhost/MyWcfService")))
.SingleInstance();builder.Register(c => c.Resolve<ChannelFactory<IMyService>>().CreateChannel()).UseWcfSafeRelease();builder.RegisterType<MyService>().As<IMyService>();
Container = builder.Build();
var address = new Uri("http://localhost:8080/MyWcfService");
var host = new ServiceHost(typeof (MyService), address);
host.AddServiceEndpoint(typeof (IMyService), new BasicHttpBinding(), string.Empty);host.AddDependencyInjectionBehavior<IMyService>(Container);host.Description.Behaviors.Add(new ServiceMetadataBehavior {HttpGetEnabled = true, HttpGetUrl = address});
return host;
}
}}and the MyService.svc file is<%@ ServiceHost Language="C#" Debug="true"
Service="WCFService.MyService, WCFService"
Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, Autofac.Integration.Wcf"%>
Thank you very much.
Daniel
--
You received this message because you are subscribed to the Google Groups "Autofac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to autofac+u...@googlegroups.com.
To post to this group, send email to aut...@googlegroups.com.
Visit this group at http://groups.google.com/group/autofac?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.