Remoting配置记录

1.适用范围:
.Net平台下服务器数据通信,支持多信道如:http,tcp,icp,自定义信道
http:默认情况下80端口未被防火墙通过。
tcp:必须配置防火墙,在内部网中使用更加有效。
IPc:最适合在单个系统上进行跨进程的通信,使用WINDOWS跨进程通信机制,速度最快。

2.简单Remoting服务器配置
TcpServerChannel tcp =new TcpServerChannel(8086);;
HttpServerChannel Http=new HttpServerChannel(8087) ;
IpcServerChannel Ipc =new IpcServerChannel("icpServer");
ChannelServices.RegisterChannel(tcp, false);
ChannelServices.RegisterChannel(Http, false);
ChannelServices.RegisterChannel(Ipc, false);
//注:rc.Hello为一个类型:加上[Serializable] 并继承MarshalByRefObjectSingleCall:不保存客户对象,使用完即删除
Singleton:服务器的所有客户共享对象
RemotingConfiguration.RegisterWellKnownServiceType(typeof(rc.Hello), "hi", WellKnownObjectMode.SingleCall);

3.客户端调用
ChannelServices.RegisterChannel(new TcpClientChannel(), false);
rc.Hello hello = (rc.Hello)RemotingServices.Connect(typeof(rc.Hello), "tcp://192.168.1.12:8086/hi");


4.使用配置文件配置 remoting.config
rc.Hello表示类名,rc表示引用的dll名称
一。已知对象服务器端
1)

 

< configuration >
  
< system.runtime.remoting >
    
< application  name ="Hello" >
      
< service >
        
< wellknown  mode ="SingleCall"  type ="rc.Hello,rc"  objectUri ="hi" >           
        
</ wellknown >
      
</ service >
      
< channels >
        
< channel  ref ="tcp"  port ="8086"  displayName ="Tcp通道" ></ channel >
        
< channel  ref ="http"  port ="8087"  displayName ="http通道" ></ channel >
        
< channel  ref ="ipc"  portName ="8086"  displayName ="ipc通道" ></ channel >
      
</ channels >
    
</ application >
  
</ system.runtime.remoting >
</ configuration >

 

 

将上述文件保存为remoting.config
服务器端执行
RemotingConfiguration.Configure("Remoting.config"文件路径,false);

2)已知对象客户端

 

< configuration >
  
< system.runtime.remoting >
    
< application  name ="Client" >
      
< service >
        
< client  displayName ="Hello client" >
        
< wellknown  type ="rc.Hello,rc"  url ="tcp://192.168.1.12:8086/hi"   />
            
</ client >
        
</ wellknown >
      
</ service >
      
< channels >
        
< channel  ref ="tcp"  displayName ="Tcp通道" ></ channel >
      
</ channels >
    
</ application >
  
</ system.runtime.remoting >
</ configuration >

 

客户端执行
RemotingConfiguration.Configure("Remoting.config"文件路径,false);
二。客户激活的对象的服务器配置
1)服务器端

ExpandedBlockStart.gif 代码
< configuration >
  
< system.runtime.remoting >
    
< application  name ="Hello" >
      
< service >
      
< activated  type ="rc.Hello,rc"   />
      
</ service >
      
< channels >
        
< channel  ref ="tcp"  port ="8086"  displayName ="Tcp通道" ></ channel >
        
< channel  ref ="http"  port ="8087"  displayName ="http通道" ></ channel >
        
< channel  ref ="ipc"  portName ="8086"  displayName ="ipc通道" ></ channel >
      
</ channels >
    
</ application >
  
</ system.runtime.remoting >
</ configuration >

 

2)客户端

ExpandedBlockStart.gif 代码
< configuration >
  
< system.runtime.remoting >
    
< application  name ="Client" >
      
< service >
        
< client  displayName ="Hello client"  url ="http://192.168.1.12:8087/hi" >
            
</ client >
        
</ wellknown >
      
</ service >
      
< channels >
        
< channel  ref ="http"  displayName ="http通道" ></ channel >
      
</ channels >
    
</ application >
  
</ system.runtime.remoting >
</ configuration >

 


 

转载于:https://www.cnblogs.com/qingyi/archive/2010/01/19/1651418.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值