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

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

问题描述

我想对当前托管在 IIS7 中的 WCF 应用程序使用 netTcpBinding,这意味着将其配置为使用 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?

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

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:

Castle Windsor 和非 HTTP 协议 WCF 服务

文章的本质是,而不是使用在 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);
   }
}

引用马特的话:

我承认我花了一段时间更详细地研究了 Host Factory,希望包装 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天全站免登陆