我差不多完成了NHibernate的一次大型升級,最終也成爲了城堡升級。我幾乎在那裏,除了ASP.NET網站不會運行,因爲我得到一個錯誤,其中ServiceSecurityContext.Current爲空。我可能是錯的(我對Castle仍然陌生),但我認爲這與我在註冊WCF設施時所做的更改有關。城堡溫莎WCF集成 - DefaultServiceHostFactory,內核等
以前(在一個叫ServiceLocator.cs類)有這樣的代碼:
/// <summary>
/// Register the WindsorServiceHostFactory with the container
/// </summary>
public static void RegisterWcfServer()
{
RegisterWcfFacility();
DefaultServiceHostFactory.RegisterContainer(Container.Kernel);
}
其中RegisterWcfFacility()方法是這樣的:
private static void RegisterWcfFacility()
{
IFacility[] facilities = Container.Kernel.GetFacilities();
bool hasWcfFacility = false;
foreach (IFacility facility in facilities)
{
if (facility.GetType() != typeof (WcfFacility))
continue;
hasWcfFacility = true;
break;
}
if (!hasWcfFacility)
Container.AddFacility<WcfFacility>();
}
隨後我已經改變了它對此(因爲我試圖讓它編譯顯然,並且DefaultServiceHostFactory不再有一個「RegisterContainer」方法):
/// <summary>
/// Register the WindsorServiceHostFactory with the container
/// </summary>
public static void RegisterWcfServer()
{
RegisterWcfFacility();
// see: http://stackoverflow.com/questions/9729395/castlewindsor-3-0-and-defaultservicehostfactory-registercontainer
// obsolete:
//DefaultServiceHostFactory.RegisterContainer(Container.Kernel);
Container.Register(Component.For<DefaultServiceHostFactory>());
}
我的「RegisterWcfFacility()」新版本看起來是這樣的:
private static void RegisterWcfFacility()
{
var facilities = Container.Kernel.GetFacilities();
var hasWcfFacility = facilities.Any(facility => facility.GetType() == typeof (WcfFacility));
if (!hasWcfFacility)
Container.AddFacility<WcfFacility>();
}
我只是張貼這主要是問的東西,如:我在完全找錯了樹?我註冊這個設施的方式是否合法?這可以解釋爲什麼我的ServiceSecurityContext.Current爲空? (是的,我已經看到了這一點):
https://groups.google.com/forum/#!topic/castle-project-devel/VOQKW4XlvLM%5B1-25%5D
感謝您的任何意見。乾杯,--Dave
也許我可以澄清我的問題...什麼是在城堡3.0語法等效,聲明:DefaultServiceHostFactory.RegisterContainer(Container.Kernel); – 2012-08-20 05:52:17
這裏的答案......請看到我的其他職位: http://stackoverflow.com/questions/12105622/castle-wcf-client-registration-syntax/12129491#12129491 – 2012-08-26 11:00:47