小弟最近学习 .net remoting ,自己写了个测试程序。
Server:IDictionary tcpProp = new Hashtable();
tcpProp["name"] = "tcp8087";
tcpProp["port"] = 8087;
IChannel channel = new TcpChannel(tcpProp,
new BinaryClientFormatterSinkProvider(),
new BinaryServerFormatterSinkProvider());
ChannelServices.RegisterChannel(channel);IDictionary tcpchannels2 = new Hashtable();
tcpchannels2["name"] = "tcp8088";
tcpchannels2["port"] = 8088;
IChannel channel2 = new TcpChannel(tcpchannels2, new BinaryClientFormatterSinkProvider(), new BinaryServerFormatterSinkProvider());
ChannelServices.RegisterChannel(channel2, true);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(MyRemotClass), "MyRemotClass", WellKnownObjectMode.SingleCall);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(tempclass), "tempclass", WellKnownObjectMode.SingleCall);
Console.WriteLine("RemotingServer……");
Console.ReadLine();
//这边我注册了2个通道,也注册2个类对象 MyRemotClass和tempclass,他们继承同一个接口MarshalByRefObject和MyRemoteInterfance(这个是我定义的接口)然后是客户端:TcpClientChannel tcc = new TcpClientChannel("ClientTcp", new BinaryClientFormatterSinkProvider());
ChannelServices.RegisterChannel(tcc);
MyRemoteInterfance mc = (MyRemoteInterfance)Activator.GetObject(typeof(MyRemoteInterfance), "tcp://localhost:8087/tempclass");
if (mc == null)
{
    Console.WriteLine("ERROR!");
}
else
{
    //Console.WriteLine(mc.GetSqlData());
    DataSet ds = mc.GetSqlData();
    string str = ds.Tables[0].Rows.Count.ToString();
    Console.WriteLine(str);
}
MyRemoteInterfance mc2 = (MyRemoteInterfance)Activator.GetObject(typeof(MyRemoteInterfance), "tcp://localhost:8088/MyRemotClass");
                
if (mc2 == null)
{
    Console.WriteLine("ERROR!");
}
else
{
    DataSet ds2 = mc2.GetSqlData();
    string str2 = ds2.Tables[0].Rows.Count.ToString();
    Console.WriteLine(str2);
}
Console.ReadLine();
//这边利用MyRemoteInterfance接口。2个类中的GetSqlData()方法都是返回一个DATASET结果发现,如果是发往第一个通道,就是端口为8087的,可以获得正确的返回值。但是发往8088的,却一直没有返回值,也没报错信息。
想请教各位大大,怎么把具体对象注册到指定的通道?

解决方案 »

  1.   

    汗,今天好多帖子,一下子沉了……  自己顶下,希望有喜欢研究.net remoting的朋友进来帮忙看看~
    谢谢楼上帮忙顶的朋友~
      

  2.   

    可以尝试两种方法一、
    IDictionary tcpProp = new Hashtable();
    tcpProp["name"] = "tcp8087";
    tcpProp["port"] = 8087;
    tcpProp["name"] = "tcp8088";
    tcpProp["port"] = 8088;IChannel channel = new TcpChannel(tcpProp,
    new BinaryClientFormatterSinkProvider(),
    new BinaryServerFormatterSinkProvider());
    ChannelServices.RegisterChannel(channel);ChannelServices.RegisterChannel(channel);这两个合一起看看
    二、
    如果服务器端注册了两个通道客户端是不是也要相应的两个通道来请求呢
    楼主试试 我是尽力了
      

  3.   

    谢谢楼上朋友支持,但是你说的第一种方法是不行的,tcpProp这样赋值后得到的只有最后一次给予的值。
    第二种方法我也尝试了下,不知道是代码没写对还是怎么的,也是没用,还是不能实现。
    不过还是非常谢谢帮助。
      

  4.   


    昨天在网上见了remoting,特感兴趣,正在学习中!
      

  5.   

    建议大家最好别用remoting 还是socket和webServices好
      

  6.   

    Remoting在学习中,希望有人帮忙解释下这个问题.谢谢各位支持~