I have a client that runs 2 threads, each of them try to access a wcf service. The service is defined using the default behavior of
AppService = new ServiceHost(typeof(MyService),
new Uri[] { new Uri(netTcpLocalhostSimple) });
AppService .AddServiceEndpoint(
typeof(IMyServiceContract),
new NetTcpBinding(SecurityMode.None),
netTcpLocalhostSimple);
In default - the behavior of the WCF service is single connection mode - meaning - it accept only 1 call at a time.
开发者_高级运维However, when I debug the server, I've found 2 worker threads processing a request simultaneously.
How can this happen - if I didn't set it ?
You're a bit off with your default assumption; by default, WCF uses a per-session approach for session-aware protocol, and NetTcp uses a transport session. For a non-session-aware protocol, per-call is used.
So each client proxy - in your case each thread - gets a separate instance of the service class, which will keep serving that particular client, as long as the session isn't terminated, by the client, by a timeout, or by a fault.
The point is: each requesting client gets its own service instance, which also means: each service instance needs to deal with only a single given client, e.g. multithreading etc. is not an issue and thus programming the service class is just that much easier.
What is it you're expecting / what do you need?
Marc
精彩评论