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 7762423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:23:55+00:00 2026-06-01T14:23:55+00:00

If I run my WCF service(hosted in II7) and uses PerSession on contextinstance, will

  • 0

If I run my WCF service(hosted in II7) and uses PerSession on contextinstance, will one session be the same as one thread? What happens while the client is not making any calls but do have a session on the service? Is the session still taking a thread?

If I change to PerCall I supose that I will get a thread per call and that this thread is returned when the call is over.

Where can I find this information?

  • 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-06-01T14:23:56+00:00Added an answer on June 1, 2026 at 2:23 pm

    I believe you can find answers and good explanations here.

    At glance you would use PerCall for scalability reasons and PerSession for usual web scenarios.

    • When using PerSession once client did first call instance of service implementation will be kept on server. Every client has it’s own session executed only on one thread (!) per client. So, yes 1 Session == 1 Thread by default. But you can also change ConcurrencyMode, so within one session client can do many concurrent calls.

    • In case of PerCall service instance will be disposed immediately after call is done.

    [EDITED (after discussions with David Nelson)]:

    (!) It doesn’t mean the same thread! It only means that ThreadPool will use available thread to run service code. But if you start 1000 concurrent clients ThreadPool will allocate many threads, which involves resources, such as memory.

    Explanation of threads usage with code:

    I created simple Calculator service to show how treading works for WCF service.

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
    public class CalculatorService : ICalculatorService
    {
        private int _threadIdOnCreating = Thread.CurrentThread.ManagedThreadId;
        public int AccumulatedValue { get; private set; }
        public int Accumulate(int valueToAdd)
        {
            AccumulatedValue += valueToAdd;
    
            Console.WriteLine(
    string.Format("Accumulated: {0}. ThreadIdOnServiceCreating:{1} CurrentThreadId:{2}",
                AccumulatedValue, _threadIdOnCreating, Thread.CurrentThread.ManagedThreadId));
    
            return AccumulatedValue;
        }
    }
    

    I run Accumulate method with parameter 2 for five times and then created new client proxy and did the same.
    Below is output, which proves that server keeps instance of service implementation (threadId on creation), but methods are run on different threads, taken from ThreadPool.

    I'm calculator
    Accumulated: 2. ThreadIdOnServiceCreating:6 CurrentThreadId:6
    Accumulated: 4. ThreadIdOnServiceCreating:6 CurrentThreadId:7
    Accumulated: 6. ThreadIdOnServiceCreating:6 CurrentThreadId:6
    Accumulated: 8. ThreadIdOnServiceCreating:6 CurrentThreadId:7
    Accumulated: 10. ThreadIdOnServiceCreating:6 CurrentThreadId:6
    Accumulated: 2. ThreadIdOnServiceCreating:9 CurrentThreadId:9
    Accumulated: 4. ThreadIdOnServiceCreating:9 CurrentThreadId:6
    Accumulated: 6. ThreadIdOnServiceCreating:9 CurrentThreadId:9
    Accumulated: 8. ThreadIdOnServiceCreating:9 CurrentThreadId:6
    Accumulated: 10. ThreadIdOnServiceCreating:9 CurrentThreadId:8
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My Application while installing will create and run a wcf service hosted on windows
I could run a Windows Service hosted WCF service listening http://localhost:80/MyService while IIS was
we run a WCF service hosted in IIS7 on Win2k8. We see the following
I have a WCF service, hosted in IIS 7.0 that needs to run database
Im creating a simple WCF service for receiving crash reports. The service will run
I have hosted one WCF Service on the Azure platform and in web.config enabled
I am newbie of wcf and mulit-thread, and I write a wcf service hosted
I have a WCF service (basicHttpBinding) hosted in II7 on Vista that I expect
I have a Web application and a WCF service hosted on the same Windows
I'm trying to run a simple WCF Service... My Wcf Service .config: <system.serviceModel> <services>

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.