IpcChannel连接问题

时间:2011-08-26 15:43:13

标签: c# c#-2.0 ipc

我在工作中使用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);

当我尝试连接“客户端”表单时,出现连接错误,说明找不到指定的文件。

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

它正在寻找远程配置文件。点击此处查看更多信息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>