您的位置:首页 > 其它

WCF深入学习_并发管理(四)

2011-04-07 15:58 330 查看
一.实例说明
(4.Instance mode =PerSession and Concurrency =Multiple)实例模式'PerSession'与并发'Multiple'。

In this combination one WCF instance is created for every WCF client session and every method call is run over multiple threads. Below is the pictorial representation of the same.



二.代码分析
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.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple)]
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);
}
}
}

三.运行结果分析
If you run the sample code attached with this article you will find same instance with every method call running on different methods.



To get a better idea you can run with different client exe instance with different names as shown below. You can notice how every client get his own WCF service instance with every method allocated to run on different threads.

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: