Проблема с подключением IpcChannel - PullRequest
0 голосов
/ 26 августа 2011

Я использую 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 голосов
/ 26 августа 2011

Это ищет файл конфигурации удаленного взаимодействия.Посмотрите здесь для получения дополнительной информации 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>
...