Chapter V does not support binding WCF sessions and concurrent instances of default

5.1 shows a list does not define any concurrent instances or acts of service, it directs WCF to use the default values, ConcurrencyMode.Single and InstanceContextMode.PerSession. When using these settings and when a binding session does not support, such as basicHttpBinding, WCF created create a new instance of each service it receives the request and execute code in its own thread. It will wait for 5 seconds before returning.
5.1 using the default list and the concurrent instances of behavior service
1 [ServiceContract]
2 public interface IStockService
3 {
4     [OperationContract]
5     double GetPrice(string ticker);
6 }
01 [ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Single, InstanceContextMode=InstanceContextMode.PerSession)]
02 public class StockService : IStockService
03  {
04      StockService()
05      {
06          Console.WriteLine("{0}:Created new instance of StockService on thread", DateTime.Now);
07      }
08      public double GetPrice(string ticker)
09      {
10          Console.WriteLine("{0}: GetPrice called on thread {1}", DateTime.Now, Thread.CurrentThread.ManagedThreadId);
11          Thread.Sleep(5000);
12          return 94.85;
13      }
14  }
   List 5.2 shows the client code calls three times GetPrice method. Client code asynchronous call this method three times and then wait before exiting all results are returned.
   Figure 5.2 shows the client (left) and server (on the right) output. Output shows three client requests are transmitted synchronously and returns the results after 5 seconds. Server output displays each client requests to create an instance of a service class and each request is handled in its own thread. Because basicHttpBinding does not support session, PerSession default behavior PerCall same. InstanceContextMode.PerSession behavioral guidance WCF for each request to create a new instance, while ConcurrencyMode.Single setup instructions WCF Each instance allows only one thread execution.
Figure 5.2 does not support binding session ConcurrencyMode default InstanceContextMode and output results


==========

forward from

 

Reproduced in: https: //www.cnblogs.com/llbofchina/archive/2011/06/30/2094041.html

Guess you like

Origin blog.csdn.net/weixin_33937778/article/details/94206802