gpt4 book ai didi

c# - channel 'tcp' 已经注册

转载 作者:太空狗 更新时间:2023-10-29 17:34:44 24 4
gpt4 key购买 nike

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

我已经写了一个基本的部分,并得到“ channel ‘tcp’已经注册”异常。我想以编程方式设置 channel 配置。

最佳答案

正如其他人所说,如果您不指定 channel 名称,代码默认使用“tcp”并且每个 channel 都必须有一个唯一的名称:因此为您打开的每个 channel 指定一个唯一的名称...

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

关于c# - channel 'tcp' 已经注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/839577/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com