使用NET.TCP绑定的Ninject WCF扩展ArgumentNullException

时间:2011-03-27 19:01:56

标签: .net wcf ioc-container ninject ninject-extensions

我有一个WCF 4服务,其中2个端点配置为使用wsHttpBinding和netTcpBinding。我使用WAS在IIS 7.5中托管服务,并使用Ninject WCF扩展到DI进入我的服务。当我使用wsHttpBinding端点来调用我的服务但是当我使用netTcpBinding时失败,我的服务工作正常。当我查看我的应用程序事件日志时,我会收到以下错误。

我已经尝试在VS2010中调试问题,但是这个问题无处可寻。如果可能的话,我不想从我的WCF服务中删除Ninject。我知道我可以使用wsHttpBinding,但我这是一个内部服务,我想获得netTcpBindings提供的性能提升。

WebHost failed to process a request.
 Sender Information: System.ServiceModel.ServiceHostingEnvironment+HostingManager/30180123
 Exception: System.ServiceModel.ServiceActivationException: The service '/ProfileService.svc' cannot be activated due to an exception during compilation.  The exception message is: Cannot be null
Parameter name: root. ---> System.ArgumentNullException: Cannot be null
Parameter name: root
   at Ninject.Infrastructure.Ensure.ArgumentNotNull(Object argument, String name) in c:\Projects\Ninject\ninject\src\Ninject\Infrastructure\Ensure.cs:line 20
   at Ninject.ResolutionExtensions.Get[T](IResolutionRoot root, IParameter[] parameters) in c:\Projects\Ninject\ninject\src\Ninject\Syntax\ResolutionExtensions.cs:line 37
   at System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses)
   at System.ServiceModel.ServiceHostingEnvironment.HostingManager.CreateService(String normalizedVirtualPath)
   at System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(String normalizedVirtualPath)
   at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)
   --- End of inner exception stack trace ---
   at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)
   at System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(String relativeVirtualPath)
 Process Name: w3wp
 Process ID: 8656

有没有人可以帮助解决这个问题?对此的任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:7)

如果我没错,我估计您可能正在使用使用KernelContainer的旧版本。您需要在Kernel上设置KernelContainer。参见:

https://github.com/ninject/ninject.extensions.wcf/blob/52bb83728774701ec42b5f76b096bec934dfe419/src/Ninject.Extensions.Wcf/KernelContainer.cs

答案 1 :(得分:4)