我們有一個Web服務,它將請求發送到託管WCF服務進行處理的Windows服務。Windows服務/ WCF和線程,初學者問題
界面簡單:
namespace MyApp
{
[ServiceContract]
public interface IMyApp
{
[OperationContract]
string DoSomething(string xml);
}
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
class MyAppWcf : IMyApp
{
public string DoSomething(string xml)
{
Customer customer = GlobalObject.GetCustomer(xml); //millisecs
return customer.DoSomething(xml); //Takes 5-10 seconds
}
}
}
GlobalObject是在WindowsService.OnStart()實例化,幷包含所有靜態數據的客戶對象需要。 界面DoSomething()將被調用到約。 30個不同的客戶。
問題:
1.什麼是現在的默認線程行爲?每次通話都必須等到最後一次通話完成?
2.什麼影響會改變InstanceContextMode?
REAL問題:
有多達1000個客戶對象,2個不同的客戶對象可以被稱爲並行,但同樣缺一不可。例如
DoSomething(「Customer 1」); =>繼續。在10秒內回答
DoSomething(「Customer 2」); =>與上述呼叫同時進行。
DoSomething(「Customer 2」); =>將等待DoSomething(「客戶2」)的最後一次呼叫完成
我的服務行爲設置應該如何,我必須實現鎖定機制以防止同時處理多個並行對象?
謝謝。
編輯2:GlobalObject.GetCustomer()只是從字典中檢索XML中提到的客戶。
感謝馬特,那看起來正是我所需要的。 – 2010-11-19 21:27:05