MS .Net Remoting框架是完全可配置的,可由配置文件定制Remoting的各种行为,下面讨论下SAOs(服务器端可激活对象的配置)的配置文件,租约与CAOs(客户端可激活对象),在实际汲及Remoting的项目中,推荐使用配置文件,这样可以简化代码,随时更改,通道,端口,URL的设置而不用重新编译程序,接下来,我们在上一个Demo的基础上,改为配置文件实现一个简单的Remoting程序

首先,看一下SAOs配置文件:
 1.Net Remoting 对象生存周期(3)<?xml version="1.0" encoding="utf-8" ?>
 2.Net Remoting 对象生存周期(3)
 3.Net Remoting 对象生存周期(3)<configuration>
 4.Net Remoting 对象生存周期(3)  <system.runtime.remoting><!--所有关于Remoting的配置,可据此在MSDN中查到Remoting的所有配置节点-->
 5.Net Remoting 对象生存周期(3)    <application>
 6.Net Remoting 对象生存周期(3)      <service><!--注册一个服务-->
 7.Net Remoting 对象生存周期(3)        <wellknown mode="Singleton" objectUrl="SsyHello" type="General.HelloServer,General"/><!--注册一个众所周知的对象,及其它各种信息-->
 8.Net Remoting 对象生存周期(3)      </service>
 9.Net Remoting 对象生存周期(3)      <channels><!--注册通道 -->
10.Net Remoting 对象生存周期(3)        <channel port="8086" ref="http"/><!--ref指引用machine.config中的配置-->
11.Net Remoting 对象生存周期(3)      </channels>
12.Net Remoting 对象生存周期(3)    </application>
13.Net Remoting 对象生存周期(3)  </system.runtime.remoting>
14.Net Remoting 对象生存周期(3)</configuration>

此时在对于Demo1中的Server端代码如下:
 1.Net Remoting 对象生存周期(3)using System;
 2.Net Remoting 对象生存周期(3)using System.Collections.Generic;
 3.Net Remoting 对象生存周期(3)using System.Text;
 4.Net Remoting 对象生存周期(3)using System.Runtime.Remoting.Channels;
 5.Net Remoting 对象生存周期(3)using System.Runtime.Remoting;
 6.Net Remoting 对象生存周期(3)using System.Runtime.Remoting.Channels.Tcp;
 7.Net Remoting 对象生存周期(3)using System.Runtime.Remoting.Channels.Http;
 8.Net Remoting 对象生存周期(3)using General;
 9.Net Remoting 对象生存周期(3)namespace Server
10

从以上可以看出,通道的定义,注册及对象在服务器上的注册等环节均用配置文件实现了,同理对于客户端如下:
配置文件:
 1.Net Remoting 对象生存周期(3)<?xml version="1.0" encoding="utf-8" ?>
 2.Net Remoting 对象生存周期(3)<configuration>
 3.Net Remoting 对象生存周期(3)  <system.runtime.remoting>
 4.Net Remoting 对象生存周期(3)    <system.runtime.remoting>
 5.Net Remoting 对象生存周期(3)      <application>
 6.Net Remoting 对象生存周期(3)        <client>
 7.Net Remoting 对象生存周期(3)          <wellknown url="http://localhost:8086/SayHello"  type="General.HelloServer,General"/>
 8.Net Remoting 对象生存周期(3)        </client>
 9.Net Remoting 对象生存周期(3)        <channels>
10.Net Remoting 对象生存周期(3)          <channel port="0" ref="http"/>
11.Net Remoting 对象生存周期(3)        </channels>
12.Net Remoting 对象生存周期(3)      </application>
13.Net Remoting 对象生存周期(3)    </system.runtime.remoting>
14.Net Remoting 对象生存周期(3)  </system.runtime.remoting>
15.Net Remoting 对象生存周期(3)</configuration>

客户端代码为:
.Net Remoting 对象生存周期(3)using System;
.Net Remoting 对象生存周期(3)
using System.Collections.Generic;
.Net Remoting 对象生存周期(3)
using System.Text;
.Net Remoting 对象生存周期(3)
using System.Runtime.Remoting.Channels.Tcp;
.Net Remoting 对象生存周期(3)
using System.Runtime.Remoting.Channels.Http;
.Net Remoting 对象生存周期(3)
using System.Runtime.Remoting.Channels;
.Net Remoting 对象生存周期(3)
using System.Runtime.Remoting;
.Net Remoting 对象生存周期(3)
using General;
.Net Remoting 对象生存周期(3)
namespace Client

远程对象及其它部分均不需改变,未完,待续....

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-12
  • 2022-12-23
  • 2022-12-23
  • 2021-05-17
  • 2021-05-31
猜你喜欢
  • 2021-08-22
  • 2022-12-23
  • 2021-11-22
  • 2021-06-15
  • 2022-12-23
  • 2021-10-14
  • 2021-05-22
相关资源
相似解决方案