我有問題,我不知道如何爲一個對象(通過WCF收到)轉發到另一個線程(例如一個WinForm)。WCF的服務事件的問題
我在類中創建服務ComManager.cs:
var wcfServer = new ServiceHost(typeof(ClientListenerService));
wcfServer.Open();
我在ClientListenerService.cs這樣的服務接口實現:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single .....)]
public class ClientListenerService : IClient
{
// This is a theoretical approach, as there is no way to forward an event handler to the service here
public event xyz;
public void AlarmTriggered(AlarmTriggeredDto dto)
{
// How do i get the object to some kind of event handler outside of this service here???
// I need sth. like:
xyz.Invoke(dto);
}
}
當方法AlarmTriggered(dto)被調用,我需要將該對象轉發到另一個線程。 我不知道如何實現這一點,因爲我不能找到一種方法,任何參數傳遞給ServiceHost的(如一個事件處理程序或某事),我ClientListenerService以後可以使用。 靜態對象/隊列的所有解決方法都不符合我的要求。
任何想法?
非常感謝!我正在嘗試這個單例實例的東西,但我不知道它必須像這樣構造! – David 2011-04-01 21:58:07
它沒有*可以這樣構建,但它允許你,因爲單例是一種特殊情況。默認情況下,WCF將在您的類上使用默認構造函數。 – 2011-04-01 22:16:43
到ServicemodelEx下載鏈接的鏈接似乎已損壞。它在http://idesign.net/Downloads/GetDownload/1887 – B4ndt 2013-01-08 10:51:02