views:

168

answers:

1

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 ?

+1  A: 

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

marc_s
Your observation is correct, (Vitaliy's comment showed me the direction and I've already fixed my problem - moving it to single instant mode), now I understand that it is depends on the protocol I choose).
Dani
btw - my problem was using a static NHibernate session object in the WCF Service, and once 2 proxies accessed the service, NH started to get messy, so I guess that static variables crosses the instance boundaries.
Dani