频道’tcp’已经注册

我希望给定的应用程序(Windows服务)充当远程服务器以及远程客户端。 在生产中,我将运行我的应用程序的两个实例,通过.NET Remoting相互监视,并相应地报告失败。

我写了一个基本的部分,并且“已经注册了’通道’tcp’”例外..我想以编程方式设置通道配置。

具有特定端口号的通道只能由一个应用程序实例创建。 您需要为每个实例使用不同的端口号和通道名称。

这需要使用单独的通道模板(如果您使用的是模板?)。

正如其他人所说,如果你没有指定频道名称,默认情况下代码使用“tcp”,每个频道都必须有一个唯一的名称:为你打开的每个频道指定一个唯一的名称……

int tcpPort = 52131; // ------------------------------------------------------------ BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider(); serverProv.TypeFilterLevel = TypeFilterLevel.Full; RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off; serverProv.TypeFilterLevel = TypeFilterLevel.Full; IDictionary propBag = new Hashtable(); // ----------------------------------------- bool isSecure = [true/false]; propBag["port"] = tcpPort ; propBag["typeFilterLevel"] = TypeFilterLevel.Full; propBag["name"] = "UniqueChannelName"; // here enter unique channel name if (isSecure) // if you want remoting comm to be secure and encrypted { propBag["secure"] = isSecure; propBag["impersonate"] = false; // change to true to do impersonation } // ----------------------------------------- tcpChan = new TcpChannel( propBag, null, serverProv); ChannelServices.RegisterChannel(tcpChan, isSecure); // -------------------------------------------- string uRI = MyUniversalResourceIndicatorName; // --------------------------------------------- RemotingConfiguration.RegisterWellKnownServiceType( typeof(ImportServiceManager), uRI , WellKnownObjectMode.SingleCall); 

每个AppDomain只能创建一个具有相同portnumber的相同通道。 这有什么不对吗?