what is the global.asax Application_Start equivalent when using WAS in IIS7

前端 未结 2 483
孤独总比滥情好
孤独总比滥情好 2020-12-02 23:07

I\'d like to use the netTcpBinding for my WCF application which is currently hosted in IIS7, which means configuring it to use WAS instead. This is fairly straight forward h

相关标签:
2条回答
  • 2020-12-02 23:32

    AppInitialize is a valid method of initializing your service. But there are some other methods that might work better for you and they are described in this article: How to Initialize Hosted WCF Services

    NOTE: the original link went away. The link above is to a copy on archive.org.

    0 讨论(0)
  • 2020-12-02 23:39

    I believe AppInitialize() is the method you're looking for. Here's an article on using it to initialise Castle Windsor in a WAS hosted WCF service:

    Castle Windsor and non-HTTP Protocol WCF Services

    The essence of the article is, instead of using Application_Start() which won't get called in WAS:

    protected void Application_Start(object sender, EventArgs e)
    {
       var container = new WindsorContainer("ioc.config");
       DefaultServiceHostFactory.RegisterContainer(container.Kernel);
    }
    

    Use:

    public class InitialiseService
    {
       /// <summary>
       /// Application initialisation method where we register our IOC container.
       /// </summary>
       public static void AppInitialize()
       {
          var container = new WindsorContainer("ioc.config");
          DefaultServiceHostFactory.RegisterContainer(container.Kernel);
       }
    }
    

    To quote Matt:

    I confess I spent a while looking at the Host Factory in more detail, looking to wrap the DefaultServiceHostFactory. However, there appears to be a far simpler solution and that is to make use of the little documented AppInitialize method. If you create a class (any class), put it into the ASP.NET App_Code folder in your project and give it a method signature as defined below, this little baby will get fired exactly when you want it to. You can then initialise your IoC container in there.

    0 讨论(0)
提交回复
热议问题