我们最近开始迁移到Castle Windsor,我在运行WCF服务时遇到了一些问题。这是一个常规的Windows服务没有在IIS中托管,我们提供SSL材料并使用自定义X509CertificateValidator
来验证客户提供的证书。
以下是我用于创建WCF服务的代码。它位于引用它的WCF服务的单独项目中。
public IWindsorContainer RegisterService<T,K>(
IServiceBehavior customBehavior,
Action<ServiceHost> onCreate = null,
Action<ServiceHost> onOpen = null,
Action<ServiceHost> onClose = null,
Action<ServiceHost> onFault = null) where T : class where K : T
{
var facility = this.AddFacility<WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero);
var serviceModel = new DefaultServiceModel()
.OnCreated(onCreate)
.OnOpened(onOpen)
.OnClosed(onClose)
.OnFaulted(onFault);
var service = Component.For<T>()
.ImplementedBy<K>()
.AsWcfService<T>(serviceModel)
.LifestylePerWcfOperation<T>();
if (customBehavior != null)
facility.Register(Component.For<IServiceBehavior>().Instance(customBehavior));
facility.Register(service);
return facility;
}
服务按预期启动(我可以使用chrome导航到服务而没有任何问题),服务正在呈现并验证SSL材料(即命中自定义验证器)但在此之后,客户端在{{{ 1}}:
FaultException
下面是我Looks like you forgot to register the http module Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule
To fix this add
<add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor" />
to the <httpModules> section on your web.config.
If you plan running on IIS in Integrated Pipeline mode, you also need to add the module to the <modules> section under <system.webServer>.
Alternatively make sure you have Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 assembly in your GAC (it is installed by ASP.NET MVC3 or WebMatrix) and Windsor will be able to register the module automatically without having to add anything to the config file.
的一小部分,我试图将模块放在通过谷歌和一些猜测建议的所有区域中:
App.Config
我几乎没有想法。有谁知道原因是什么?如果没有,任何人都可以解释更多关于我得到的错误? 任何帮助将不胜感激!
答案 0 :(得分:6)
我再次回答自己的问题(发布后的第二天,亲爱的):P
此处出现此错误消息(感谢上帝开源!):
tldr - 见下文:
public class PerWebRequestLifestyleModule : IHttpModule
{
...
private static void EnsureInitialized()
{
if (initialized)
{
return;
}
var message = new StringBuilder();
message.AppendLine("Looks like you forgot to register the http module " + typeof(PerWebRequestLifestyleModule).FullName);
message.AppendLine("To fix this add");
message.AppendLine("<add name=\"PerRequestLifestyle\" type=\"Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor\" />");
message.AppendLine("to the <httpModules> section on your web.config.");
if (HttpRuntime.UsingIntegratedPipeline)
{
message.AppendLine(
"Windsor also detected you're running IIS in Integrated Pipeline mode. This means that you also need to add the module to the <modules> section under <system.webServer>.");
}
else
{
message.AppendLine(
"If you plan running on IIS in Integrated Pipeline mode, you also need to add the module to the <modules> section under <system.webServer>.");
}
#if !DOTNET35
message.AppendLine("Alternatively make sure you have " + PerWebRequestLifestyleModuleRegistration.MicrosoftWebInfrastructureDll +
" assembly in your GAC (it is installed by ASP.NET MVC3 or WebMatrix) and Windsor will be able to register the module automatically without having to add anything to the config file.");
#endif
throw new ComponentResolutionException(message.ToString());
}
...
}
由此我很快收集到问题是PerWebRequestLifestyleModule
没有被初始化,这对我来说没问题,因为我不需要它来提供这项服务!
进一步查看我自己的代码,为我们的Web服务器,bingo使用它们时,我的一些为此服务加载的存储库被设置为使用LifestylePerWebRequest
!
将它们调整为其他东西后(在这种情况下&#39; LifestylePerWcfOperation`)一切正常。