Remoting学习之配置篇

     
      使用配置文件的好处是什么?很简单,他可以简化代码,可以随时更改,通道,端口,URL的设置不需要重新编译就可以运行。所以在实际项目中经常采用这种方式。
怎么写一个服务器端的配置文件?
下面举个例子:
<configuration>
  <system runtime remoting>   ///配置的都是与remoting有关的内容
    <application>  ///可以包含多个application
       <serive>//表示在我的一个程序中注册了一个service
        <wellknown mode="Singleton" ObjectUri="HelloNewegg"  ///ObjectUri为访问这个对象的地址
         type="Newegg.RAM,Accounting"/>   ///type表示对象的类型;Newegg.RAM表示这个类的名字;
                                                                   ///Accounting表示程序集,实际表现为一个DLL
        </serive>
        <channels>//可以在里面注册多个通道
             <channel port="8888" ref="http"/>  ///ref表示引用了machine.config本身http不是在这个配置文件里配置的
        </channels>
    </application>
  </system runtime remoting>
</configuration>
怎么写一个客户器端的配置文件?
<configuration>
  <system runtime remoting> ///配置的都是与remoting有关的内容
    <application>  ///可以包含多个application
       <client>//示在我的一个程序中注册了一个service
        <wellknown  ObjectUri="http://localhost:8888/HelloNewegg"
         type="Newegg.RAM,Accounting"/>  
                                         
        </client>
        <channels>
             <channel port="0" ref="http"/> //port="0"什么意思?表示客户端不用探听任何端口。
        </channels>
    </application>
  </system runtime remoting>
</configuration>

使用配置文件的代码怎么写??
服务器端:RemotingConfiguration.Configure("NeweggServer.exe.config");///NeweggServer表示服务器端的工程名
          有时候也这样写:
            string cfg=AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
            RemotingConfiguration.Configure(cfg);
客户端:RemotingConfiguration.Configure("NeweggClient.exe.config");///NeweggClient表示客户器端的工程名
           RAM obj=new RAM();
           .......

posted on 2006-03-03 17:05  kim  阅读(1871)  评论(1编辑  收藏  举报

导航