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());     
  • 相关阅读:
    [SpringCloud] Hystrix原理及应用
    Excel框设置下拉选项
    The program no longer exists.
    win10 指纹登录修改用户密码
    git 比较两个分支内容差异
    C++ 已知两个时间(年月日)求日期差
    SELECT INTO 和 INSERT INTO SELECT 两种表复制语句详解(SQL数据库和Oracle数据库的区别)
    SQL Server查询优化方法
    xshell连接ubuntu虚拟机的方法
    beyond compare添加Java反编译插件
  • 原文地址:https://www.cnblogs.com/shenshiting/p/5025422.html
Copyright © 2011-2022 走看看