I would like to know how to make use of SharpArch.WcfClient.Castle.WcfSessionFacility as an alternative to the following verbose-ness.
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(te开发者_如何学Pythonrritories);
}
The above code has been taken from the TerritoriesController class in SharpArchitecture's NorthWind Sample.
Awaiting Nabeel
You need to:
Make sure that Windsor knows to call ComponentDestroyed for your client proxies, and that your proxies are registered with "ManageWcfSessions" set to true. Since I'm using it in a web application, I register my client proxies to use a Lifestyle of PerWebRequest:
container .Register(AllTypes.FromThisAssembly() .BasedOn(typeof(ClientBase<>)) .WithService.DefaultInterface() .Configure(c => c .LifeStyle.Is(LifestyleType.PerWebRequest) .ExtendedProperties(new { ManageWcfSessions = true })) );
Add the facility:
container.AddFacility<WcfSessionFacility>(WcfSessionFacility.ManageWcfSessionsKey);
Add the HttpModule to enable the PerWebRequest lifestyle (I can't figure out how to get stackoverflow to format this right - you'll get the idea):
add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor"
精彩评论