调用RemoteConfiguration.Configure(CONFIGFILE)修改后的设置? [英] Modify settings after calling RemoteConfiguration.Configure(configFile)?
问题描述
我的应用程序调用 RemotingConfiguration.Configure()
来建立.NET远程处理。但是,由于我所需要的信道元素的portName特性的每个应用程序运行的时间是不同的,我一定要编程配置这个特殊的设置。
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).
到目前为止,我有:
RemotingConfiguration.Configure(Program.ConfigFilePath, false);
IChannel[] regChans = ChannelServices.RegisteredChannels;
IpcChannel ipcChannel = (IpcChannel)ChannelServices.GetChannel(regChans[0].ChannelName);
调试器显示我, ipcChannel._serverChannel._prop
将在哈希表,而我需要添加一个条目,如 [PORTNAME ] = uniquePortName
,但我根本无法看出如何访问和修改此。
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.
我知道我随时可以放弃的* config文件,做了整个事情编程,但我的真正的不想丢掉其大部分的设置容易编辑的好处。
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.
时为时已晚修改 IpcClientChannel
对象一旦 RemotingConfiguration.Configure()
返回?很显然,我大概可以写我自己的版本 RemotingConfiguration.Configure()
,但这似乎并不像正确的方式做事情要么。
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.
推荐答案
我想我已经确定了我想做的事是不可能的。
I think I've established that what I wanted to do is not possible.
您可以的或者的使用 RemotingConfiguration.Configure()
的或的是这样的:
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.
(当然,你仍然可以读取任何从* .config文件这些设置,但问题是,你必须明确地code为大家可能希望支持的选项。)
(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.)
这篇关于调用RemoteConfiguration.Configure(CONFIGFILE)修改后的设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!