C# 如何确定远程通道是否已经注册
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1167290/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to determine if remoting channel is already registered
提问by Randy Klingelheber
In my ASP.NET application, I have a line in the global application start event that configures the client remoting channel by calling RemotingConfiguration.Configure().
在我的 ASP.NET 应用程序中,我在全局应用程序启动事件中有一行通过调用 RemotingConfiguration.Configure() 来配置客户端远程处理通道。
This works well the first time, but when my web application gets recycled, the application start event is fired again causing the following remoting exception:
这在第一次运行良好,但是当我的 Web 应用程序被回收时,应用程序启动事件再次被触发,导致以下远程处理异常:
Remoting configuration failed with the exception 'System.Runtime.Remoting.RemotingException: The channel 'tcp' is already registered.
远程配置失败,出现异常“System.Runtime.Remoting.RemotingException:通道“tcp”已注册。
I would like to detect if the channel is already configured so that I can avoid getting this exception.
我想检测通道是否已配置,以便我可以避免出现此异常。
采纳答案by John Rusk
Try ChannelServices.RegisteredChannels
尝试 ChannelServices.RegisteredChannels
回答by John Saunders
But what would you do if you found it was already registered?
但是如果你发现它已经被注册了,你会怎么做?
In any case, I just wanted to make sure you knew that .NET Remoting has been deprecated in favor of WCF.
无论如何,我只是想确保您知道 .NET Remoting 已被弃用而支持 WCF。
回答by samwa
I've been having this problem too.
我也一直有这个问题。
The trouble is that you can stop the application that called RemotingConfiguration.Configure() but that doesn't make the channel available. Its something to do with ports or it might just be the name of the channel, I'm not sure.
问题是您可以停止调用 RemotingConfiguration.Configure() 的应用程序,但这不会使通道可用。它与端口有关,或者它可能只是通道的名称,我不确定。
The solution I found which seems to work is to get the registered channels and unregister the channel you want to remove.
我发现似乎有效的解决方案是获取已注册的频道并取消注册要删除的频道。
Here is some code
这是一些代码
RemotingConfiguration.Configure(appConfig, false);
// do this to unregister the channel
IChannel[] regChannels = ChannelServices.RegisteredChannels;
IChannel channel = (IChannel)ChannelServices.GetChannel(regChannels[0].ChannelName);
ChannelServices.UnregisterChannel(channel);
RemotingConfiguration.Configure(appConfig, false); // this is just a test to see if we get an error
I hope this works for you, it has for me
我希望这对你有用,它对我有用