【问题标题】:Modify settings after calling RemoteConfiguration.Configure(configFile)?调用 RemoteConfiguration.Configure(configFile) 后修改设置?
【发布时间】:2010-11-18 14:14:41
【问题描述】:

我的应用程序调用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() 版本,但这似乎也不是正确的做事方式。

【问题讨论】:

    标签: .net remoting configuration-files .net-remoting


    【解决方案1】:

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

    你可以或者使用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 文件中读取任何这些设置,但关键是您必须为您可能想要支持的所有选项显式编码。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-08
      • 1970-01-01
      • 2014-07-25
      • 1970-01-01
      • 2021-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多