上一次我们使用编码的方式配置Remoting连接,今天我们将说利用配置文件配置Remoting连接,至于用配置文件的好处我就不多说了,现在我们来看:
服务器端配置文件:
.Net REmoting(4)配置文件<?xml version="1.0" encoding="utf-8" ?>
.Net REmoting(4)配置文件
<configuration>
.Net REmoting(4)配置文件  
<system.runtime.remoting>
.Net REmoting(4)配置文件    
<application>
.Net REmoting(4)配置文件      
<service>
.Net REmoting(4)配置文件        
<wellknown 
.Net REmoting(4)配置文件                    mode
="Singleton" 
.Net REmoting(4)配置文件                    type
="General.HelloServer, General" 
.Net REmoting(4)配置文件                    objectUri
="SayHello" />
.Net REmoting(4)配置文件      
</service>
.Net REmoting(4)配置文件      
<channels>
.Net REmoting(4)配置文件        
<channel port="8090" ref="http"/>
.Net REmoting(4)配置文件      
</channels>
.Net REmoting(4)配置文件    
</application>
.Net REmoting(4)配置文件  
</system.runtime.remoting>
.Net REmoting(4)配置文件
</configuration>
.Net REmoting(4)配置文件
以上的配置节点表示的意思我就不用多说了,跟编码配置文件意义一样。
那么我们怎么加载这个配置文件呢?有两种方法:
第一种:直接指定备件文件路径
.Net REmoting(4)配置文件 RemotingConfiguration.Configure(@"C:\Documents and Settings\gj1\My Documents\Visual Studio 2005\Projects\ConsoleApplication1\ConsoleApplication1\App.config");

第二种:
.Net REmoting(4)配置文件
.Net REmoting(4)配置文件            RemotingConfiguration.Configure(
.Net REmoting(4)配置文件            AppDomain.CurrentDomain.SetupInformation.ConfigurationFile
.Net REmoting(4)配置文件            );

客户端的配置文件:
在Web.Config里加入:
.Net REmoting(4)配置文件  <system.runtime.remoting>
.Net REmoting(4)配置文件    
<application>
.Net REmoting(4)配置文件      
<client>
.Net REmoting(4)配置文件        
<wellknown type="HelloServer, General" url="http://localhost:8090/SayHello" />
.Net REmoting(4)配置文件      
</client>
.Net REmoting(4)配置文件      
<channels>
.Net REmoting(4)配置文件        
<channel ref="http" port="0"></channel>
.Net REmoting(4)配置文件      
</channels>
.Net REmoting(4)配置文件    
</application>
.Net REmoting(4)配置文件  
</system.runtime.remoting>

加载客户端的配置文件跟服务器端一样。
DEMO实现功能跟昨天一样,只是注册方式变成了利用配置文件
完整代码下载

相关文章: