net Remoting(4)——配置文件

简介: RemotingConfiguration类进行类型注册时,可以采用程序配置方式,也可以通过配置文件来进行。这个类有一个Configure方法: public static void Configure(     string filename,     bool ensureSecurity...

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/

转载请注明:博客园

目录
相关文章
|
网络协议
一起谈.NET技术,回顾.NET Remoting分布式开发
  记得在下第一次接触.NET Remoting分布式开发是在2003年,那时候是Framework1.0初次亮相之时,Remoting分布式开发是Framework1.0其中一个亮点。经过多年的发展,在2005年,WCF随着Framework2.0首先亮相。
2599 0
|
6月前
|
JSON 数据格式
.net core 读取配置文件的几种方式
# 一、Json配置文件 ## 1、这里的配置文件指的是下图 ![请在此添加图片描述](https://developer-private-1258344699.cos.ap-guangzhou.myqcloud.com/column/article/5877188/20231031-c79281ce.png?x-cos-security-token=Agam0Cn5pDWzx5RjFFzmFp5SXifE2lwa11a1f9dbaeac346ddc3b179889543979Cq1MFNxd9AGUyz-E0xgqW-YuUxnToKOaIzGnWLMcgCmVO4YvDOI5Os41fWu
66 0
.net core 读取配置文件的几种方式
|
8月前
.net 6 中使用Autofac
.net 6 中使用Autofac
146 0
|
9月前
|
XML 存储 JSON
.Net Core基础之读取配置文件
.Net Core基础之读取配置文件
108 0
|
容器
五:.net core(.NET 6)使用Autofac实现依赖注入
Autofac的简单使用:由于将来可能引用很多包,为了保持统一队形,我们再新建一个类库项目Wsk.Core.Package,当做包的引用集合:
531 0
五:.net core(.NET 6)使用Autofac实现依赖注入
|
数据可视化 搜索推荐 API
七、.net core(.NET 6)使用Serilog进行配置和实现日志记录
使用Serilog来实现日志记录先安装Serilog六件套神装包:
1541 0
七、.net core(.NET 6)使用Serilog进行配置和实现日志记录
|
网络协议
回顾“.NET技术”.NET Remoting分布式开发
  记得在下第一次接触.NET Remoting分布式开发是在2003年,那时候是Framework1.0初次亮相之时,Remoting分布式开发是Framework1.0其中一个亮点。经过多年的发展,在2005年,WCF随着Framework2.0首先亮相。
1412 0
|
Web App开发 C# Windows
一起谈.NET技术,.Net Framework Client Profile 和 .Net Framework
.NET Framework Client Profile是.NET Framework的裁剪版本。它面向客户端应用程序。它提供 Windows Presentation Foundation (WPF)、Windows 窗体、Windows Communication Foundation (WCF)和 ClickOnce 功能的简化子集。
1052 0
|
数据格式 .NET 开发框架
.NET Core 读取配置文件
前面写过一篇《.NET Core类库中读取配置文件》 ,当时对于.NET Core读取配置文件了解有限,这里做下补充: 配置文件内容如下: { "url": "homeinns.com", "person": { "name": "xfh", "age": 26 } } 引用Microsoft.
2381 0