Mediar.framework--使用反射来声明Remoting wellknown服务

        使用 Remoting 时,每有一个服务,就要声明一次。虽然 Remoting  支持配置文件方式声明,但是写起来依然很麻烦。象我这样的懒人最不想做的就是这种重复的机械劳动。于是寻找出一种简洁的方式——使用反射。反射只有在启动时执行,所以也不会影响效率。
 
None.gif static  TcpChannel chan;
None.gif
None.gif    
public   static   void  RegisterServer( int  port)
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {            
InBlock.gif
InBlock.gif        chan 
= new TcpChannel(port);
InBlock.gif        RemotingConfiguration.ApplicationName 
= "DataAccess";
ExpandedSubBlockStart.gifContractedSubBlock.gif        ChannelServices.RegisterChannel(chan, 
false /**//*ensureSecurity*/);        
InBlock.gif
InBlock.gif
InBlock.gif        
foreach (string var in System.IO.Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory))
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (var.EndsWith(".dll"))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                RegisterServer(var);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }
      
InBlock.gif     
ExpandedBlockEnd.gif    }

None.gif
None.gif    
private   static   void  RegisterServer( string  path)
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif        Assembly Ass;
InBlock.gif        Ass 
= Assembly.LoadFrom(path);
InBlock.gif
InBlock.gif        Type[] t 
= Ass.GetTypes();
InBlock.gif        
foreach (Type tt in t)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (typeof(DataAccess).IsAssignableFrom(tt))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Console.WriteLine(
" Register Class: " + tt.FullName);
InBlock.gif                RemotingConfiguration.RegisterWellKnownServiceType(tt, tt.FullName, WellKnownObjectMode.SingleCall);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif      }

ExpandedBlockEnd.gif}

None.gif

这里的DataAccess 类是继承MarshalByRefObject,在程序里是基类,其它的业务类,可以必需继承DataAccess

 

 

客户端

remoteURL = "tcp://" + mRemoteServer + ":" + mRemotePort + "/" + mDataAccessTypeName;

     da = Activator.GetObject(t, remoteURL);

 

DataAccess mDataAccess = ((DataAccess)(da));


  相关:
    Mediar.Framework --一个MVC架构
     Mediar.Framework --对象mapping 
     Mediar.Framework--使用反射来声明Remoting wellknown服务
     Mediar.Framework -- 业务的实现1(UI的绑定)

转载于:https://www.cnblogs.com/mediar/archive/2006/09/12/501946.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值