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

2

3

4

5

6

7

8

9

10

11

12

13

14

此时在对于Demo1中的Server端代码如下:
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4
using System.Runtime.Remoting.Channels;
5
using System.Runtime.Remoting;
6
using System.Runtime.Remoting.Channels.Tcp;
7
using System.Runtime.Remoting.Channels.Http;
8
using General;
9
namespace Server
10
{
11
public class Server
12
{
13
/// <summary>
14
/// 第二步,创建服务器端
15
/// </summary>
16
/// <param name="args"></param>
17
/// <returns></returns>
18
static int Main(string[] args)
19
{
20
////Remoting内置的两种通道,也可自定义自己的通道
21
//TcpChannel tcpChannel = new TcpChannel(8085);//tcp通道
22
//HttpChannel httpChannel = new HttpChannel(8086);//http通道
23
24
25
////服务器端对通道进行注册,注册完后,服务器就对通道进行监听
26
//ChannelServices.RegisterChannel(tcpChannel,false);
27
//ChannelServices.RegisterChannel(httpChannel,false);
28
29
////把远程对象注册到服务器上,注册众所周知的服务类型,WellKnown---都是服务器激活的对象
30
//RemotingConfiguration.RegisterWellKnownServiceType(typeof(HelloServer),"SayHello",WellKnownObjectMode.Singleton);
31
///*
32
// * Singleton 服务器端只产生单例,任何请求共用,保存状态,
33
// * Singlecall 客户端一个请求对应一个实例,没有状态
34
// *
35
// *
36
// *
37
// *
38
//*/
39
string path = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;//得到APP.confg文件在程序可执行目录下生成的server.exe.config文件的路径
40
RemotingConfiguration.Configure(path);
41
Console.Write("服务器开始监听

,按任意銉退出");
42
Console.ReadLine();
43
return 0;
44
}
45
}
46
}
47

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41




42

43

44

45

46

47

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

2

3

4

5

6

7

8

9

10

11

12

13

14

15

客户端代码为:


























































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