IpcChannel连接问题

本文关键字:问题 连接 IpcChannel | 更新日期: 2023-09-27 18:06:57

我在工作中使用IPC使服务程序与用户程序通信。我无法让用户连接到服务程序IPC。

下面是我的代码:

服务器:

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);

当我尝试连接我的"客户端"表单时,我得到一个连接错误,说明它找不到指定的文件。

谢谢你的帮助!

IpcChannel连接问题

查找远程配置文件。点击这里获取更多信息http://msdn.microsoft.com/en-us/library/ms973907.aspx

基本上你需要添加这样的东西到服务器

<configuration>
  <system.runtime.remoting>
    <application>
      <service>
        <activated type="Hello.AddService, Hello"/>
      </service>
    </application>
  </system.runtime.remoting>
</configuration>

,像这样发送给客户端

<configuration>
  <system.runtime.remoting>
    <application>
      <client url="http://localhost:8000>
        <activated type="Hello.AddService, Hello"/>
      </client>
    </application>
  </system.runtime.remoting>
</configuration>