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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:23:32+00:00 2026-05-13T22:23:32+00:00

I have a WCF service that I am calling from multiple clients. I need

  • 0

I have a WCF service that I am calling from multiple clients. I need to store and manage a value globally. On my service I have the following attributes:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single)]

In my service I have something similar to this:

private static int counter;

public void PrintCounter()
{
    counter++;
    StreamWriter sw = new StreamWriter(@"C:\outFile.txt", true);
    sw.WriteLine("Counter: " + counter);
    sw.Close();
}

With my limited knowledge of WCF, I would presume that I have a Singleton service and the fact that my private variable is static, that all calls to the service would use the same object.

However, when I look at my log output, I see the following:

Counter: 1
Counter: 1

What I expected to see would be:

Counter: 1
Counter: 2

Am I missing something to make this work the way I need it to? Do I need to store objects in some sort of cache? Any help is greatly appreciated.

I can post more coded if needed.

  • 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-13T22:23:33+00:00Added an answer on May 13, 2026 at 10:23 pm

    Since it’s a singleton service, e.g. only one instance will ever exists of it, why don’t you make this a regular class member variable??

    Since the ConcurrencyMode is set to single, too – you don’t even have to worry about concurrent access to the variable.

    On the other hand – singleton with ConcurrencyMode=Single is a recipe for a really really slow service which might become a bottleneck quickly – so you might want to program your code in such a way that it would also work under ConcurrencyMode=Multiple with potentially concurrent access to the member variable.

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

Sidebar

Related Questions

I have a WCF service that I have to reference from a .net 2.0
I have a WCF service that I call from a windows service. The WCF
I have a Windows program that calling a WCF service. This service after a
Does anyone have any good examples of calling a WCF service from a classic
I have a WCF service that calls the following method in one of my
When calling a WCF service from Silverlight that works for smaller parameters, but fails
I am calling a WCF service from some stub. The issue is that, I
I need to make multiple asynchronous calls from inside a wcf service hosted in
I have a WCF service that takes as a parameter a string value name.
I have a WCF Service that should not enter the faulted state. If there's

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.