在IIS7中使用WAS时,global.asax Application_Start等效项是什么 [英] what is the global.asax Application_Start equivalent when using WAS in IIS7

查看:107
本文介绍了在IIS7中使用WAS时,global.asax Application_Start等效项是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将netTcpBinding用于当前托管在IIS7中的WCF应用程序,这意味着将其配置为使用WAS.但是,这很简单,我的应用程序以前使用了global.asax文件中的Application_Start事件.我不需要访问httpContext(据我所知,访问权限已在IIS7中删除),但是我还是想了解一下start或init方法吗?

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 however, my application previously made use of the Application_Start event in the global.asax file. I do not require access to the httpContext(which I understand access has been removed in IIS7), however I would still like to hook into the start or init methods?

在与IIS7相对应的WAS中托管应用程序时,是否存在等效项?

Does an equivalent exist when hosting an application in WAS as apposed to IIS7?

使用经典模式不是一种选择(同样,我对httpcontext不感兴趣,并且仅在使用http绑定的情况下才起作用)-我已经看到了一个将静态类放置在app_code文件夹中的示例看起来像一个可怕的骇客.

Using classic mode is not an option(again I'm not interested in the httpcontext and this only appears to work if using an http binding) - and I've seen an example of putting a static class instide the app_code folder which looks like a horrible hack.

推荐答案

我相信AppInitialize()是您要寻找的方法.这是有关使用它在WAS托管的WCF服务中初始化Castle Windsor的文章:

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:

本文的本质是,而不是使用在WAS中不会被调用的Application_Start():

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

使用:

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

引用马特:

我承认我花了一段时间详细研究了主机工厂, 寻找包装DefaultServiceHostFactory.但是,出现 成为一个简单得多的解决方案,那就是利用 已记录的AppInitialize方法.如果您创建一个班级(任何班级), 将其放入项目中的ASP.NET App_Code文件夹中,并给它一个 方法签名如下定义,这个小宝宝将被解雇 正是您想要的时间.然后,您可以初始化您的IoC 在那里的容器.

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.

这篇关于在IIS7中使用WAS时,global.asax Application_Start等效项是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆