IIS/WAS 托管的非 HTTP WCF 服务中初始化代码的正确位置?
据我了解,为 net.msmq 配置的 WCF 服务在 IIS/WAS 中托管时不会作为 HttpApplication 运行,这意味着您无法获取 Global 中的事件(Application_Start 是重要的事件)。我在这方面正确吗?
使用 Windows Server AppFabric 自动启动服务是否会通过 HTTP 访问服务,导致 Application_Start 事件触发?如果是这样,这可靠吗?
我想我的真正问题是,非 HTTP WCF 服务的初始化代码的“正确”位置在哪里?
特别是(因为不同的东西正确的位置可能不同):
- IoC 注册
- log4net 初始化
- 验证本地是否存在 MSMQ 队列(正如 Juval Lowy 在他的 WCF 书中所建议的那样)
后续问题:自定义 IServiceBehavior 中的事件是否会在每个请求上触发或者只在启动时一次? ServiceHost.OnOpening() 怎么样 - 每次请求还是仅在启动时一次? (我的测试显示它只有一次,但是有人知道 WCF“生命周期”的记录在哪里,因为我似乎无法在任何地方找到它。)
It is my understanding that a WCF service configured for net.msmq will not run as an HttpApplication when hosted in IIS/WAS, which means you don't get the events in Global (Application_Start being the important one). Am I correct in this regard?
Does using Windows Server AppFabric to auto-start the service hit the service over HTTP, causing the Application_Start event to fire? If so, is this reliable?
I guess my real question is, where is the "proper" place for initialization code for a non-HTTP WCF service?
Particularly (since the right place may be different for different stuff):
- IoC registrations
- log4net initialization
- Verifying the MSMQ queue exists locally (as Juval Lowy suggests in his WCF book)
Follow-on question: Do the events in a custom IServiceBehavior fire on every request or only once at startup? What about ServiceHost.OnOpening() - every request or only once at startup? (My testing shows it's only once, but does anyone know where the WCF "lifecycle" is documented, because I can't seem to find it anywhere.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我无法验证 IIS/WAS 中托管的 WCF 服务是否无法配置为支持 Application_Start,但不需要执行您想要的操作。我建议您创建一个自定义 ServiceHost 与一个自定义 ServiceHostFactory(用于 WAS)。此方法记录在 MSDN 文章 和 这篇博文。使用这种方法,您可以将服务托管在 IIS/WAS、Windows 服务或控制台应用程序中,因为初始化过程是相同的。
I can't verify that WCF services hosted in IIS/WAS can't be configured to support Application_Start but it is not required to do what you want. I'd recommend you create a custom ServiceHost in conjunction with a custom ServiceHostFactory (for WAS). This approach is documented in an MSDN article and this blog post. Using this approach, you can host your service in IIS/WAS, a Windows Service or a console app because the initialization process will be the same.