How to determine if remoting channel is already registered

守給你的承諾、 提交于 2019-12-13 12:09:49

问题


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

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:

Remoting configuration failed with the exception 'System.Runtime.Remoting.RemotingException: The channel 'tcp' is already registered.

I would like to detect if the channel is already configured so that I can avoid getting this exception.


回答1:


Try ChannelServices.RegisteredChannels

http://msdn.microsoft.com/en-us/library/system.runtime.remoting.channels.channelservices.registeredchannels(VS.71).aspx




回答2:


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.

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




回答3:


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.



来源:https://stackoverflow.com/questions/1167290/how-to-determine-if-remoting-channel-is-already-registered

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