WCF Overview ServiceBehaviorProperty ConcurrencyMode

I would like to understand the property ServiceBehavior.ConcurrencyMode.

Consider the following code from the service side:

[ServiceContract]
public interface IMySercice {
   [OperationContract]
   int mycall(int a);
}
/*** HERE I WILL GENERATE Two variants of this code ***/
[ServiceBehaviour(InstanceContext = InstanceContextMode.Single)]
public class MyService : IMyService {
   // Constructors...
   // implementations of interface
   public int mycall(int a) { ... }
}
class Program {
   static void Main(string[] args) {
      MyServiceMyS = new MyService(...); /* Creating service instance */
      Uri MyUri = new Uri("http://services.mycompany.com/services/"); /* Base address for my hosted service */
      using (ServiceHost host = new ServiceHost(MyS)) { /* Defining service host, configuration file contains info regarding endpoints, not shown here for clarity */
         host.Start();
         host.Stop();
      }
   }
}

Now consider what I would call this service, please consider 10 machines on the Internet that can call me. At some point it happens that these 10 machines ALL MAKE 10 simultaneous requests for int mycall(int a). I would like to study these scenarios:

SCENARIO 1

...
/*** VARIANT 1 ***/
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single, InstanceContext = InstanceContextMode.Single)]
public class MyService : IMyService {
   ...
}
...

SCENARIO 2

...
/*** VARIANT 2 ***/
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContext = InstanceContextMode.Single)]
public class MyService : IMyService {
   ...
}
...

So, there are 10 simultaneous calls ... what happens in both cases? Please tell me whether I am right or wrong:

1, , 10 . ( ) . 2 WCF 10 .

, ?

+3
2

10 10 . , ConcurrencyMode InstanceContextMode. InstanceContextMode , WCF - , :

  • PerCall -
  • PerSession -
  • Single - singleton -

, , InstanceContextMode.Single, - PerCall , (basicHttpBinding, webHttpBinding, wsHttpBinding ) PerSession , ( netTcpBinding, netNamedPipeBinding, wsHttpBinding ).

ConcurrencyMode , . , PerCall instancing Multiple concurrency Single concurrency, concurrency.

+6

, InstanceContextMode.Single , , , . 10 , - , 10 MaxConcurrentSessions ServiceThrottlingBehavior ( "" - , ).

0

All Articles