我想知道如何利用SharpArch.WcfClient.Castle.WcfSessionFacility作为以下详细信息的替代方法。
public ActionResult Index() {
IList<TerritoryDto> territories = null;
// WCF service closing advice taken from http://msdn.microsoft.com/en-us/library/aa355056.aspx
// As alternative to this verbose-ness, use the SharpArch.WcfClient.Castle.WcfSessionFacility
// for automatically closing the WCF service.
try {
territories = territoriesWcfService.GetTerritories();
territoriesWcfService.Close();
}
catch (CommunicationException) {
territoriesWcfService.Abort();
}
catch (TimeoutException) {
territoriesWcfService.Abort();
}
catch (Exception) {
territoriesWcfService.Abort();
throw;
}
return View(territories);
}
以上代码取自SharpArchitecture的NorthWind Sample中的TerritoriesController类。
等待 纳比尔
答案 0 :(得分:1)
你需要:
确保Windsor知道为您的客户端代理调用ComponentDestroyed,并且您的代理注册时将“ManageWcfSessions”设置为true。由于我在Web应用程序中使用它,我注册我的客户端代理以使用PerWebRequest的Lifestyle:
container
.Register(AllTypes.FromThisAssembly()
.BasedOn(typeof(ClientBase<>))
.WithService.DefaultInterface()
.Configure(c => c
.LifeStyle.Is(LifestyleType.PerWebRequest)
.ExtendedProperties(new { ManageWcfSessions = true }))
);
添加设施:
container.AddFacility<WcfSessionFacility>(WcfSessionFacility.ManageWcfSessionsKey);
添加HttpModule以启用PerWebRequest生活方式(我无法弄清楚如何让stackoverflow格式化这个 - 你会得到这个想法):
add name =“PerRequestLifestyle”type =“Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule,Castle.Windsor”