技术开发 频道

.NET Remoting分布式开发之经典总结篇

  最后在客户端对远程对象进行调用

  using System.Runtime.Remoting.Channels;

  using System.Runtime.Remoting.Channels.Tcp;

  using Model;

  using Manager;

  namespace Client

  {

  class Program

  {

  static void Main(string[] args)

  {

  //确立通道传送方式

  ChannelServices.RegisterChannel(new TcpClientChannel(),false);

  //使用Activator.GetObject()或者Activator.CreateInstance()方法建立透明代理,控制远程对象

  PersonManager personManager = (PersonManager)Activator.GetObject(typeof(PersonManager), "tcp://localhost:8089/PersonUri");

  //获取远程数据

  List personList = personManager.GetList();

  Console.Write(personList.Count);

  Console.ReadKey();

  }

  }

  }

 

  六、总结

  上面已经为大家介绍了一个简单的Remoting开发实例。利用Remoting实现分布式开发,可以对远程对象的生命周期进行管理,利用HttpChannel,HttpServerChannel,HttpServerTransportSink,HttpClientChannel,HttpClientTransportSinkProvider,HttpClientTransportSink等对象控制服务器端和客户端的通道,使用代理、消息接收器与通道接收器对信息进行管理,在下面几章将为各位一一介绍。

0
相关文章