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

 

这样就可以了。


本文出自勇哥的网站《少有人走的路》wwww.skcircle.com,转载请注明出处!讨论可扫码加群:

发表评论:

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

会员中心
搜索
«    2024年4月    »
1234567
891011121314
15161718192021
22232425262728
2930
网站分类
标签列表
最新留言
    热门文章 | 热评文章 | 随机文章
文章归档
友情链接
  • 订阅本站的 RSS 2.0 新闻聚合
  • 扫描加本站机器视觉QQ群,验证答案为:halcon勇哥的机器视觉
  • 点击查阅微信群二维码
  • 扫描加勇哥的非标自动化群,验证答案:C#/C++/VB勇哥的非标自动化群
  • 扫描加站长微信:站长微信:abc496103864
  • 扫描加站长QQ:
  • 扫描赞赏本站:
  • 留言板:

Powered By Z-BlogPHP 1.7.2

Copyright Your skcircle.com Rights Reserved.

鄂ICP备18008319号


站长QQ:496103864 微信:abc496103864