技术开发 频道

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

  using System.Runtime.Remoting;

  using System.Runtime.Remoting.Channels;

  using System.Runtime.Remoting.Channels.Tcp;

  using Model;

  using Manager;

  namespace Server

  {

  class Program

  {

  static void Main(
string[] args)

  {

  
//建立服务传输方式,可选择TCP或者HTTP,前者更能发挥高效性

  TcpServerChannel channel
= new TcpServerChannel(8089);

  
//注册通道

  ChannelServices.RegisterChannel(channel,
false);

  
//添加可调用的远程对象,WellKonwnObjectMode可选择为SingleTon或者SingleCall

  RemotingConfiguration.RegisterWellKnownServiceType(typeof(PersonManager),
"PersonTcp", WellKnownObjectMode.Singleton);

  Console.ReadKey();

  }

  }

  }

  第二,可以在config文件里面实现服务器的配置,其效果与代码实现的相同。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  
<system.runtime.remoting>
    
<application name="Server">
      
<service>
        
//定义传送模式,远程对象类,Uri路径
        
<wellknown mode="Singleton"  type="Manager.PersonManager,Manager" objectUri="PersonUri"/>
      
</service>
      
<channels>
        
//定义传送通道,传送方式和接口
        
<channel ref="tcp" port="8089"/>
      
</channels>
    
</application>
  
</system.runtime.remoting>
</configuration>
0
相关文章