我在作業中使用IPC來使服務程序與用戶程序進行通信。我不能讓用戶連接到服務程序IPC。IpcChannel連接問題
這裏是我的代碼:
服務器:
string name = application + "-" + cie + "-" + instance ;
IDictionary properties = new Hashtable();
properties.Add("authorizedGroup", "Utilisateurs");
properties.Add("name", "CI.EventChannel");
properties.Add("portName", name);
if (ChannelServices.GetChannel(name) != null)
ChannelServices.UnregisterChannel(ChannelServices.GetChannel(name));
channel = new IpcServerChannel(properties,null);
ChannelServices.RegisterChannel(channel, true);
//Register this service type.
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(IpcServerMethodsEventGenerator),
"IpcServerMethodsEventGenerator", WellKnownObjectMode.Singleton);
客戶:
IDictionary properties = new Hashtable();
properties.Add("authorizedGroup", "Utilisateurs");
properties.Add("name", "CI.EventChannel");
properties.Add("portName", ipc); //ipc values "EventGenerator-002-1"
ipc = "ipc://" + ipc;
//Create an IPC client channel.
IpcClientChannel channel = new IpcClientChannel(properties,null);
//Register the channel with ChannelServices. (channel, security)
if (ChannelServices.GetChannel(channel.ChannelName) != null)
ChannelServices.UnregisterChannel(ChannelServices.GetChannel(channel.ChannelName));
ChannelServices.RegisterChannel(channel, true);
//Register the client type.
if (register)
RemotingConfiguration.RegisterWellKnownClientType(typeof(IpcServerMethodsEventGenerator), ipc);
當我試圖用我的 「客戶端」 形式的連接,我得到一個連接錯誤,說明它找不到指定的文件。
謝謝你的幫助!
我已經做了幾個錯誤。它正在工作。我顛倒了客戶端和服務器上的通道名稱和端口名稱,並且我在客戶端和服務器上都使用了相同的通道名稱,現在我知道這是錯誤的。 –