少有人走的路

勇哥的工业自动化技术网站

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);

 

这样就可以了。


发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

«    2026年2月    »
1
2345678
9101112131415
16171819202122
232425262728
控制面板
您好,欢迎到访网站!
  查看权限
网站分类
搜索
最新留言
文章归档
网站收藏
友情链接

Powered By Z-BlogPHP 1.7.3

Copyright www.skcircle.com Rights Reserved.

鄂ICP备18008319号


站长QQ:496103864 微信:abc496103864