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());     
  • 相关阅读:
    C#读写者线程(用AutoResetEvent实现同步)(转载)
    详解大端模式和小端模式(转载)
    C/C++程序员应聘试题剖析(转载)
    strcpy和memcpy的区别(转载)
    基于mini2440的Qt移植
    分布式服务以及跨平台开发清单(全栈之路)
    软件开发模式对比(瀑布、迭代、螺旋、敏捷)
    大数开方 ACM-ICPC 2018 焦作赛区网络预赛 J. Participate in E-sports
    啊啊
    括号问题
  • 原文地址:https://www.cnblogs.com/shenshiting/p/5025422.html
Copyright © 2011-2022 走看看