2009-05-08 150 views
9

我希望给定的应用程序(Windows服务)充当远程处理服务器以及远程处理客户端。在生产中,我将通过.NET Remoting运行我的应用程序的两个互相监视实例,并相应地报告故障。通道'tcp'已经注册

我写了一个基础件,并获得“渠道‘TCP’已注册” exception..I要以编程方式设置的通道配置。

回答

7

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

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

+0

服务器/客户端的端口为二fferent .. – 2009-05-08 12:44:29

+0

@Kururram Aziz - 所以每个实例打开不同的端口(而不是每个实例打开多个端口,但使用不同的端口)? – stevehipwell 2009-05-08 12:55:54

+0

@Khurram Aziz - 你有两个使用不同名称的频道吗? – stevehipwell 2009-05-08 12:58:35

2

只能创建一个具有相同端口号每一次AppDomain相同的信道。那是什么错误?

+0

似乎... 服务1有“生命体征”服务器侦听端口,在9001和服务2有“生命体征”服务器在端口9002监听服务1将检查服务2的生命体征和服务2将检查服务1 如果我不以一个实例中运行的服务器并检查其他的就很好地工作......但我想每个 – 2009-05-08 12:46:26

12

正如其他人所说,如果不指定通道名称,代码默认情况下使用“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); 
+1

“int tcpPort = 82131;” WTF。 82131,65535? – Behrooz 2010-03-29 16:44:08

相关问题