通过Spring.net发布Remoting

   Spring.Services程序集中提供了对Remoting的支持,使用Spring.net可以方便的发布和使用Remoting服务。

1.Remoting发布(服务端)
(1)首先在config文件中注册通道:

<system.runtime.remoting>
    
<application>
      
<channels>
        
<channel ref="tcp" port="8100" >
          
<serverProviders>
            
<provider ref="wsdl" />
            
<formatter ref="soap" typeFilterLevel="Full" />
            
<formatter ref="binary" typeFilterLevel="Full" />
          
</serverProviders>
          
<clientProviders>
            
<formatter ref="binary" />
          
</clientProviders>
        
</channel>
      
</channels>
    
</application>
  
</system.runtime.remoting>


(2)通过配置发布Remoting对象:
   这里我们以SAO的方式发布Remoting对象。

      <object id="gamesBoard" type="GameRabbit.Platform.Management.GamesBoard,GameRabbit.Platform">
      
</object>

      
<object name="saoGamesBoard" type="Spring.Remoting.SaoExporter,Spring.Services">
        
<property name="TargetName" value="gamesBoard" />
        
<property name="ServiceName" value="GamesBoard" />
      
</object>


(3)在程序启动时,初始化Remoting配置:

      RemotingConfiguration.Configure("EntityTest.exe.config");



2.Remoting订阅(客户端)

     <object name="remoteGamesBoard" type="Spring.Remoting.SaoFactoryObject, Spring.Services">
        
<property name="ServiceInterface">
          
<value>GameRabbit.Platform.Management.IGamesBoard, GameRabbit.Platform</value>
        
</property>
        
<property name="ServiceUrl">
          
<value>tcp://localhost:8100/GamesBoard</value>
        
</property>
      
</object>


说明:(2008-07-16)
1.Spring发布的remoting对象不需要从MarshalByRefObject继承,也不需要设置remoting对象的生存期(spring将其设为无限长)。Spring采用为对象添加动态代理的方式来做到这点。
2.如果是注册到服务器然后用于回调的Remoting对象,必须从MarshalByRefObject继承,而且还要设置生存期,否则可能出现在服务端回调的时候出现“找不到对应的服务”的错误。

posted @   zhuweisky  阅读(4646)  评论(7编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· [AI/GPT/综述] AI Agent的设计模式综述
点击右上角即可分享
微信分享提示