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/

    转载请注明:博客园

  • 相关阅读:
    python中的unlink
    if
    python中if __name__ == '__main__'
    rename函数
    win2003的密钥
    url
    python中的os.stat
    python中的mysql
    防火墙
    网址
  • 原文地址:https://www.cnblogs.com/jams742003/p/1691456.html
Copyright © 2011-2022 走看看