一.总体结构
有9并发性和实例相结合的方法如下面的表中所示。
二.实例说明
(1.Instance mode = Per Call and Concurrency = Single)实例模式'PerCall'与并发'Single'是WCF中是默认设置。
With per call new WCF instances are created for every method calls made to the WCF server service. The default concurrency is single so
only one thread will be used to serve all instances.
Below is a simple pictorial representation of what will happen in per call and single concurrency scenario:
For every client instance a single thread will be allocated.
For every method call a new service instance will be created.
A single thread will be used to serve all WCF instances generated from a single client instance.
三.代码分析
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ServiceModel; using System.ServiceModel.Description; using System.Threading; namespace ClassLibrary1 { [ServiceContract] public interface IHelloWorldService { [OperationContract(IsOneWay = true)] void Call(string ClientName); } [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single)] public class HelloWorldService : IHelloWorldService { public int i; public void Call(string ClientName) { i++; Console.WriteLine("Client name :" + ClientName + " Instance:" + i.ToString() + " Thread:" + Thread.CurrentThread.ManagedThreadId.ToString() + " Time:" + DateTime.Now.ToString() + "\n\n"); Thread.Sleep(5000); } } }
四.运行结果分析