Modify settings after calling RemoteConfiguration.Configure(configFile)?

让人想犯罪 __ 提交于 2019-12-10 11:49:23

问题


My application calls RemotingConfiguration.Configure() to set up .NET Remoting. But since I need the portName attribute of the channels element to be different each time the application is run, I have to configure this particular setting programatically.

It sounds very simple (and probably is - but I've been searching Google all day for an answer).

So far I have:

RemotingConfiguration.Configure(Program.ConfigFilePath, false);

IChannel[] regChans = ChannelServices.RegisteredChannels;
IpcChannel ipcChannel = (IpcChannel)ChannelServices.GetChannel(regChans[0].ChannelName);

The debugger shows me that ipcChannel._serverChannel._prop would be the hash table to which I need to add an entry such as ["portName"] = uniquePortName, but I simply cannot see how to access and modify this.

I know I could always scrap the *.config file and do the whole thing programatically, but I really don't want to throw away the benefits of having most of the settings easily editable.

Is it too late to modify an IpcClientChannel object once RemotingConfiguration.Configure() has returned? Obviously I could probably write my own version of RemotingConfiguration.Configure(), but that doesn't seem like the Right Way to do things either.


回答1:


I think I've established that what I wanted to do is not possible.

You can either use RemotingConfiguration.Configure() or something like:

  IDictionary channelProperties = new Hashtable();
  channelProperties.Add("authorizedGroup", "Everyone");
  channelProperties.Add("portName", "Client-" + Guid.NewGuid().ToString()); // Unique port name
  IpcChannel channel = new IpcChannel(channelProperties, null, null);
  ChannelServices.RegisterChannel(channel);

You can't mix and match. At least, that seems to be the case.

(Of course you can still read any of these settings from the *.config file, but the point is you have to explicitly code for all of the options you might want to support.)



来源:https://stackoverflow.com/questions/4215664/modify-settings-after-calling-remoteconfiguration-configureconfigfile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!