我很新的WCF和試圖瞭解各種實例管理技術,我能夠了解每個呼叫&單身實例模式,但我很困惑在每個會話實例模式,在這種情況下,爲每個客戶都創建一個單獨的會話?但它不是發生在我的情況:WCF實例管理 - PerSession模式
我的WCF服務: -
[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession)]
public class CounterService : ICounterService
{
int _counter = 0;
public int GetCount()
{
_counter++;
return _counter;
}
}
客戶端代碼: -
static void Main(string[] args)
{
CounterServiceReference.CounterServiceClient proxy = new CounterServiceReference.CounterServiceClient();
CounterServiceReference.CounterServiceClient proxy1 = new CounterServiceReference.CounterServiceClient();
Console.WriteLine("WCF Instance mode: Per Session");
Console.WriteLine("Invoking WCF service...");
Console.WriteLine("Counter: {0}", proxy.GetCount());
Console.WriteLine("Counter: {0}", proxy.GetCount());
Console.WriteLine("Counter: {0}", proxy.GetCount());
Console.WriteLine("---------------------------------------");
Console.WriteLine("Counter: {0}", proxy1.GetCount());
Console.WriteLine("Counter: {0}", proxy1.GetCount());
Console.WriteLine("Counter: {0}", proxy1.GetCount());
Console.ReadKey();
}
但是,控制檯顯示的結果爲1,1,1 --- 1,1,1但我認爲應該是1,2,3 --- 1,2,3 我在哪裏錯了?請幫忙! TIA
你沒有顯示客戶電話 - 不可能知道那裏發生了什麼... –
添加客戶端代碼 –