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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:49:40+00:00 2026-05-15T06:49:40+00:00

I am having trouble in configuring WCF service to run in session mode. As

  • 0

I am having trouble in configuring WCF service to run in session mode. As a test I wrote this simple service :

[ServiceContract]
public interface IService1
{
    [OperationContract]
    string AddData(int value);
}

[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession)]
internal class Service1 : IService1,IDisposable
{
    private int acc;

    public Service1()
    {
        acc = 0;
    }

    public string AddData(int value)
    {
        acc += value;
        return string.Format("Accumulator value: {0}", acc);
    }

    #region IDisposable Members

    public void Dispose()
    {           
    }

    #endregion
}

I am using Net.TCP binding with default configuration with reliable session flag enabled.
As far as I understand , such service should run with no problems in session mode.
But , the service runs as in per call mode – each time I call AddData , constructor gets called before executing AddData and Dispose() is called after the call.
Any ideas why this might be happening? Perhaps I am missing something?

note : I do not know if it is related , but I am using VS2008 to run this.

Update: I’ve noticed here that wcftestclient does not maintain session with clients – maybe it was my problem. Indeed that was the problem. Connecting to the service from simple console client confirmed that the service works as it should.

  • 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-15T06:49:41+00:00Added an answer on May 15, 2026 at 6:49 am

    Try requiring a SessionMode when defining the ServiceContract:

    [ServiceContract(SessionMode = SessionMode.Required)]
    public interface IService1
    {
      [OperationContract]
      string AddData(int value);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having trouble with this..I'm sure I'm missing something simple but I simply want the
I'm having trouble configuring Postfix to deliver e-mail via relay to Sendgrid. I get
Having trouble framing this assertion in Rspec for my rails app. A User has
i am having trouble configuring mysql database to connect to the right file. I
I'm having trouble with a web service deployed on Tomcat. During peak traffic times
Having trouble getting this syntax right: SELECT DISTINCT id FROM metadata WHERE (meta_key =
Having trouble with this -- a couple of other related posts out there, but
I'm having serious trouble configuring my OpenLDAP server to have the memberOf overlay enabled.
I'm having big trouble in configuring Ruby and MySQL on MacOSX. Just a fact,
Having trouble with an sql statement to retrieve a record between two timestamps. This

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.