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());     
  • 相关阅读:
    Putty完全使用方法
    TCP端口扫描
    XSS学习笔记
    SQL漏洞学习笔记
    Codeforces Round #263 (Div. 1)
    hdu4987A simple probability problem.(凸包)
    Codeforces Round #262 (Div. 2)
    hdu3228Island Explorer
    hdu2297Run(凸包的巧妙应用)
    poj3301Texas Trip(三分)
  • 原文地址:https://www.cnblogs.com/shenshiting/p/5025422.html
Copyright © 2011-2022 走看看