in the process of creating a WCF service I ran into a term that’s new to me. Basically when specifying the InstanceContextMode I have a few options, including; PerSession, PerCall and Single. Here’s the code from the sample I’m learning from:
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
public class EvalService : IEvalService { ...
Now, he stated by doing this that only one instance of my service would be created at runtime. What does this mean? I thought that everytime a connection was made to the web service that it was treated as a seperate instance.
Does it persist, this instance of my service, for every request made? Judging by the other members mentioned in the docs, is it safe to assume this is the way it works?
Per the docs:
So there is only one instance, and it’s not cleaned up after a call is made. This is like a Singleton for your WCF service. So you need to be careful about shared memory and resources.
To answer your question – yes, this is the way it works.
UPDATE Added sample:
I modified a few samples from MSDN to show the effects of
InstanceContextMode.Single. You’ll see the operation count will continue to increment even though I use two different clients. If I change theInstanceContextModetoPerCall, the count will be different (it will be zero).self-hosted service:
client: