我的問題是我想要一個服務器應用程序(在遠程計算機上)將某些事件發佈到多個客戶端計算機。服務器和客戶端使用.Net-Remoting進行通信,所以目前我使用遠程.Net-Events獲取功能。但是有一個缺點:當服務器(事件發佈者)脫機並重新啓動時,由於遠程對象引用無效,客戶端會丟失連接。.Net 2.0:如何使用臨時訂閱在遠程計算機上訂閱事件發佈者?
我正在調查鬆散耦合事件和瞬態COM訂閱來解決此問題。我將一個小型演示應用程序與一個發佈者和兩個訂閱者放在一起。它在一臺電腦上運行非常漂亮。
我正在使用COMAdmin庫爲事件訂閱者創建臨時訂閱。代碼如下所示:
MyEventHandler handler = new MyEventHandler();
ICOMAdminCatalog catalog;
ICatalogCollection transientCollection;
ICatalogObject subscription;
catalog = (ICOMAdminCatalog)new COMAdminCatalog();
transientCollection = (ICatalogCollection)catalog.GetCollection("TransientSubscriptions");
subscription = (ICatalogObject)transientCollection.Add();
subscription.set_Value("Name", "SubTrans");
subscription.set_Value("SubscriberInterface", handler);
string eventClassString = "{B57E128F-DB28-451b-99D3-0F81DA487EDE}";
subscription.set_Value("EventCLSID", eventClassString);
string sinkString = "{9A616A06-4F8D-4fbc-B47F-482C24A04F35}";
subscription.set_Value("InterfaceID", sinkString);
subscription.set_Value("FilterCriteria", "");
subscription.set_Value("PublisherID", "");
transientCollection.SaveChanges();
handler.Event1 += OnEvent1;
handler.Event2 += OnEvent2;
我現在的問題是:我需要更改訂閱才能通過網絡完成此項工作?它甚至有可能嗎?