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.