问题描述
我想将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);
}
}
引用马特:
这篇关于在IIS7中使用WAS时,global.asax Application_Start等效项是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!