帮助! - DefaultServiceHostFactory 在 application_startup 和容器创建之前执行

发布于 2024-11-02 06:15:04 字数 1112 浏览 6 评论 0原文

我正在将 WCF 工具用于 WAS 中托管的服务(iis7 中的 net.tcp 绑定),并且仅在冷应用程序启动(即尚未运行)时遇到奇怪的问题。

以下语句应在容器首次实例化时执行。

DefaultServiceHostFactory.RegisterContainer(c.Kernel);

请求服务时,我在 WCF 跟踪文件中收到以下异常

Kernel was null, did you忘记调用 DefaultServiceHostFactory.RegisterContainer()

问题似乎是 ServiceHostFactory 正在尝试创建实例在创建我的容器之前服务主机的信息。

注意:

  • 此异常发生在 Application_Start 执行之前。
  • 如果应用程序正在运行(并且容器已初始化),则服务将按预期运行。可以通过 HTTP 访问相应的 IIS 站点或从 Visual Studio 启动调试会话来启动应用程序。

重现问题的步骤

  • 发出 IISReset 以关闭所有 IIS 应用程序池。
  • 调用有问题的服务
  • WCF 跟踪输出:

    System.ServiceModel.ServiceActivationException:由于编译期间出现异常,无法激活服务“/abcd.svc”。异常消息是:调用的目标已抛出异常.. ---> System.Reflection.TargetInitationException:调用目标已引发异常。 ---> System.ArgumentNullException:内核为空,您是否忘记调用 DefaultServiceHostFactory.RegisterContainer() ? 参数名称:内核 在 Castle.Facilities.WcfIntegration.WindsorServiceHostFactory`1..ctor(IKernel 内核) 在 Castle.Facilities.WcfIntegration.DefaultServiceHostFactory..ctor()

I am using the WCF facility for a service hosted in WAS (net.tcp binding in iis7) and experiencing a weird issue only upon a cold application startup (i.e. not already running).

The following statement should be executed upon first instantiation of my container.

DefaultServiceHostFactory.RegisterContainer(c.Kernel);

When the service is requested, I get the following exception in my WCF tracefile

Kernel was null, did you forgot to call DefaultServiceHostFactory.RegisterContainer()

The issue appears to be that the ServiceHostFactory is attempting to create an instance of the service's host before my container has been created.

Note:

  • This exception is happening BEFORE the Application_Start is executed
  • If the application is running (and the container has been initialised) then the service will operate as expected. The application can be started by going to the appropriate IIS site over HTTP or starting a debugging session from Visual Studio.

Steps to recreate issue

  • Issue a IISReset to shutdown all IIS app pools.
  • Call the service in question
  • WCF tracing spits out:

    System.ServiceModel.ServiceActivationException: The service '/abcd.svc' cannot be activated due to an exception during compilation. The exception message is: Exception has been thrown by the target of an invocation.. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentNullException: Kernel was null, did you forgot to call DefaultServiceHostFactory.RegisterContainer() ?
    Parameter name: kernel
    at Castle.Facilities.WcfIntegration.WindsorServiceHostFactory`1..ctor(IKernel kernel)
    at Castle.Facilities.WcfIntegration.DefaultServiceHostFactory..ctor()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぃ弥猫深巷。 2024-11-09 06:15:04

问题在于 global.asax 及其所有方法仅与 HTTP 处理相关。顺便提一句。 global.asax 中的类派生自 HttpApplication ,这应该使这一点非常清楚。一旦您在 WAS 中托管应用程序(这是基于 net.tcp 的绑定的情况),您就无法使用这些方法。尝试使用AppInitialize之类的东西。

The problem is that global.asax and all its methods are related only to HTTP processing. Btw. class in global.asax is derived from HttpApplication which should make this pretty clear. Once you host application in WAS (which is case of net.tcp based binding) you can't use these methods. Try to use something like AppInitialize.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文