Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 665089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:40:17+00:00 2026-05-13T23:40:17+00:00

I know the use of WCF in SA is deprecated because it will move

  • 0

I know the use of WCF in SA is deprecated because it will move to SA Contrib. But until it has, I guess I have to use the support in SA.

That said, I have a problem with the underlying NHibernate session being closed after calling a WCF service. My repository’s DbContext.Session is closed after the first call so I cannot call my service more than once during a single HTTP request.

I’ve set up WCF in my project based on the Northwind sample application. The sample only calls a WCF service once per request so this problem doesn’t show up there. The problem is easily reproduced though, by duplicating the following line in the
TerritoriesController:

territories = territoriesWcfService.GetTerritories();

This throws an ObjectDisposedException: “Session is closed! Object
name: ‘ISession'”.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:40:18+00:00Added an answer on May 13, 2026 at 11:40 pm

    I managed to solve it.

    By inspecting the SharpArch.Wcf source code, I found that before the WCF service response is sent, it always closes all NHibernate sessions. This in its self is a good thing.

    In addition, I found that my client proxy factories only fired once per web request, while the second service call should induce a new proxy instance. The result was that the second service call would fail because the underlying NHibernate session was closed already. I solved that by decorating my client proxy classes with the Castle.Core.TransientAttribute, which leaves the lifetime management up to the factory that creates the client. The result of that is that our proxy factories get called every time a proxy is requested.

    Second, I had to register the proxies like this (in the ComponentRegistrar class):

    container.AddFacility("WcfSessionFacility", new WcfSessionFacility());
    
    container.Kernel.AddComponentWithExtendedProperties(
        "AccountService",
        typeof(IAccountService),
        typeof(AccountServiceClient),
        new Dictionary<string, object>()
            {
                { WcfSessionFacility.ManageWcfSessionsKey, true }
            });
    

    The WcfSessionFacility manages closing/aborting of the client, depending on its state. This makes sure the client channel is closed whenever the client proxy is destroyed so we don’t need to put our calls in try-catch blocks.

    Like me, you might think to configure lifetime management while adding the component instead of using an attribute but apparently there is no suitable overload of AddComponentWithExtendedProperties that allows this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Now i know to use the method of float.Parse but have bumped into a
I know that similar questions have been asked all over the place, but I'm
I have a problem that I'd like to solve, but I don't know how
We are currently working on an application that will use a WCF service. The
I am architecting a solution that will use WCF to make all the computers
I know you use the C based networking API to do FTP communication but
I know and use eric meyer CSS reset, but is there any more things
I would like to try Silex but i've some questions. I know to use
I know how to use new Date(UTCStrings) to local timezone. But now, the question
I need to know whether it is rule of thumb to use WCF webservice

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.