调用 RemoteConfiguration.Configure(configFile) 后修改设置?

发布于 2024-10-03 03:38:24 字数 814 浏览 7 评论 0原文

我的应用程序调用 RemotingConfiguration.Configure() 来设置 .NET Remoting。但由于我需要每次运行应用程序时通道元素的 portName 属性都不同,因此我必须以编程方式配置此特定设置。

这听起来很简单(也可能是——但我一整天都在谷歌上搜索答案)。

到目前为止,我已经:

RemotingConfiguration.Configure(Program.ConfigFilePath, false);

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

调试器向我显示 ipcChannel._serverChannel._prop 将是我需要向其添加条目的哈希表,例如 ["portName"] = uniquePortName,但我根本不知道如何访问和修改它。

我知道我总是可以废弃 *.config 文件并以编程方式完成整个事情,但我真的不想放弃大多数设置易于编辑的好处。

一旦 RemotingConfiguration.Configure() 返回后修改 IpcClientChannel 对象是否为时已晚?显然,我可以编写自己版本的 RemotingConfiguration.Configure(),但这似乎也不是正确的做法。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡淡の花香 2024-10-10 03:38:24

我想我已经确定我想做的事情是不可能的。

您可以使用RemotingConfiguration.Configure()类似的东西:

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

您不能混合搭配。至少,情况似乎是这样。

(当然,您仍然可以从 *.config 文件中读取任何这些设置,但要点是您必须为您可能想要支持的所有选项显式编码。)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文