开发者

IpcChannel connection problem

开发者 https://www.devze.com 2023-03-30 20:29 出处:网络
I\'m using IPC at job to make a Service Program communicate with a user program.I can\'t get to have the user connect to the service program IPC.

I'm using IPC at job to make a Service Program communicate with a user program. I can't get to have the user connect to the service program IPC.

Here's my code :

Server :

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开发者_StackOverflow中文版(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);

Client :

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

When I try to connect with my "client" form, I get a connection error, stating it can't find specified file.

Thank you for your help!


Its looking for a remoting cofiguration file. Look here for more info http://msdn.microsoft.com/en-us/library/ms973907.aspx

basically you need to add something like this to the server

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

and like this to the client

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

精彩评论

暂无评论...
验证码 换一张
取 消