zoukankan      html  css  js  c++  java
  • . Net Remoting体系结构(2) 远程对象 编程方式

    1 创建服务器通道

      并在.Net Remotion运行时注册该通道

      注册一个知名对象客户端激活对象

     1            TcpServerChannel channel = new TcpServerChannel(9000);
     2 
     3             ChannelServices.RegisterChannel(channel, false);
     4             //远程对象1 知名对象
     5             //WellKnownServiceTypeEntry remObj = new WellKnownServiceTypeEntry(
     6             //    typeof(MyRemoteObject), "MyRemoteObject", 
     7             //    WellKnownObjectMode.Singleton);
     8            //RemotingConfiguration.RegisterWellKnownServiceType(remObj);
     9 
    10             //远程对象2 客户端激活对象
    11             ActivatedServiceTypeEntry remObj = new ActivatedServiceTypeEntry(
    12                  typeof(MyRemoteObject));
    13             RemotingConfiguration.RegisterActivatedServiceType(remObj);
    14             
    15             Console.ReadKey();

    2 客户端端

      

     1             TcpClientChannel channel = new TcpClientChannel();
     2                 ChannelServices.RegisterChannel(channel,false);
     3                 //方式 1  知名对象
     4                 //WellKnownClientTypeEntry entry = new WellKnownClientTypeEntry(typeof(MyRemoteObject),
     5                 //    "tcp://localhost:9000/MyRemoteObject");
     6                 //RemotingConfiguration.RegisterWellKnownClientType(entry);
     7                 //MyRemoteObject obj = new MyRemoteObject();
     8                
     9                 //方式 1 客户端激活对象 调用默认无参构造
    10                 //ActivatedClientTypeEntry entry = new ActivatedClientTypeEntry(
    11                 //   typeof(MyRemoteObject), "tcp://localhost:9000");
    12                 //RemotingConfiguration.RegisterActivatedClientType(entry);
    13                 //MyRemoteObject obj = new MyRemoteObject();
    14 
    15                 
    16                 //方式 2 知名对象
    17                 //MyRemoteObject obj = (MyRemoteObject)Activator.GetObject(typeof(MyRemoteObject),
    18                 //    "tcp://localhost:9000/MyRemoteObject");
    19 
    20                 //方式 2 客户端激活对象 调用有参构造
    21                 MyRemoteObject obj = (MyRemoteObject)Activator.CreateInstance(
    22                     typeof(MyRemoteObject), new Object[]{333}, new object[]{new UrlAttribute("tcp://localhost:9000")});
    23                 Console.WriteLine(obj.Hello());
    24                 Console.WriteLine(obj.Hello());     
  • 相关阅读:
    69.广搜练习:  最少转弯问题(TURN)
    51..分治算法练习:  4378 【Laoguo】循环比赛
    50.分治算法练习:  二分算法:  2703 奶牛代理商 XII
    [转载]双向广搜
    49.分治算法练习:  1497 取余运算
    48.贪心练习:  1621 混合牛奶
    47..贪心  失恋28天-追女孩篇
    46.贪心算法练习:  区间合并
    45.分支算法练习:  7622:求排列的逆序数
    44.分治算法练习:  一元三次方程求解
  • 原文地址:https://www.cnblogs.com/shenshiting/p/5025422.html
Copyright © 2011-2022 走看看