zoukankan      html  css  js  c++  java
  • net Remoting(4)——配置文件

    RemotingConfiguration类进行类型注册时,可以采用程序配置方式,也可以通过配置文件来进行。这个类有一个Configure方法:

    public static void Configure(

        string filename,

        bool ensureSecurity

    )

    Filename就就文件名(配置文件的文件名),第二个参数用于选择安全性的启用与否

     

    在服务端激活下用配置文件来实现:

    在控制台应用程序下添加SelfService.config文件(一个文件),添加以下内容:

     

    <?xml version="1.0" encoding="utf-8" ?>

    <configuration>

      <system.runtime.remoting>

        <application name="ServerRemoting">

          <service>

            <wellknown mode="Singleton"

    type="SelfRemote.selfRemoteObject,SelfRemote"

    objectUri="selfRemoteObject"/>

          </service>

          <channels>

            <channel ref="http" port="10001"/>

          </channels>

        </application>

      </system.runtime.remoting>

    </configuration>

     

    在这个文件中,通道注册,类型注册与程序中对应。然后把此文件的 复制到输出目录 设置为 始终复制(为的就是在生成的控制台应用程序同级目录,能够找得到这个配置文件)。

     

    然后,在控制台可以:

    Console.WriteLine("http 通道remoting服务开始……");

    RemotingConfiguration.Configure("SelfService.config", false);

    onsole.Read();

     

    这样就可以了。

     

    在客户端,如果采用客户端激活方式,那么同上差不多,同时也要保证在程序同级目录能找到文件(始终复制):

    新建立ClientService.config文件,文件内容为:

    <?xml version="1.0" encoding="utf-8" ?>

    <configuration>

      <system.runtime.remoting>

        <application name="ServerRemoting">

          <service>

            <wellknown mode="Singleton"

    type="SelfRemote.selfRemoteObject,SelfRemote"

    objectUri="selfRemoteObject"/>

          </service>

          <channels>

            <channel ref="http"/>

          </channels>

        </application>

      </system.runtime.remoting>

    </configuration>

     

    这里的channel不要再指定端口。

    在测试中:

    RemotingConfiguration.Configure("ClientService.config",false);

    selfRemoteObject app1 = new selfRemoteObject();

    Assert.AreEqual(0, app1.Unid);

     

    这样就可以了。

     

    博客园大道至简

    http://www.cnblogs.com/jams742003/

    转载请注明:博客园

  • 相关阅读:
    c语言练习17——输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数
    c语言练习16——输入两个正整数m和n,求其最大公约数和最小公倍数
    c语言练习15——条件运算符的嵌套
    c语言练习14——将一个正整数分解质因数
    CentOS下Cassandra集群搭建
    一台linux服务器挂载另外一台linux服务器文件系统
    zabbix分布式监控多网段的部署与实现
    CentOS安装MySQL详解
    vcenter 7.0 安装 vRealize Operations Manager
    Zabbix分布式部署详细
  • 原文地址:https://www.cnblogs.com/jams742003/p/1691456.html
Copyright © 2011-2022 走看看