开发者

How to use SharpArch.WcfClient.Castle.WcfSessionFacility

开发者 https://www.devze.com 2023-01-11 07:31 出处:网络
I would like to know how to make use of SharpArch.WcfClient.Castle.WcfSessionFacility as an alternative to the following verbose-ness.

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:

  1. 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 }))
            );
    
  2. Add the facility:

        container.AddFacility<WcfSessionFacility>(WcfSessionFacility.ManageWcfSessionsKey);
    
  3. 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"

0

精彩评论

暂无评论...
验证码 换一张
取 消