首先,看一下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
2
3
4
5
6
7
8
9
10
从以上可以看出,通道的定义,注册及对象在服务器上的注册等环节均用配置文件实现了,同理对于客户端如下:
配置文件:
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
客户端代码为:
远程对象及其它部分均不需改变,未完,待续....