remoting初步认识(转)
也许大家都知道webservice,但很多程序员并不知道remoting,更别说分清两者的区别
两者其实原理上是差不多的,但是不同的是webservice只能通过http协议的,而remoting比较灵活,即可以http还可以tcp,而tcp的效率比较高一些,但它必须要求两边都为.net程序,而webservice不要求,也不要求另一边的操作系统。所以webservice应用的也要广泛一些。
我建议还是采用Web Service好些,对于开发来说更容易控制
Remoting一般用在C/S的系统中,Web Service是用在B/S系统中
后者还是各语言的通用接口
相同之处就是都基于XML
- 为了能清楚地描述Web Service 和Remoting之间得区别,我打算从他们的体系结构上来说起:
Web Service大体上分为5个层次:
1. Http传输信道
2. XML的数据格式
3. SOAP封装格式
4. WSDL的描述方式
5. UDDI - 概括的说Remoting与Web Services的区别是:
(1)既支持TCP信道又支持HTTP信道,传输速度快
(2)即可传输XML的SOAP包又可传输二进制流,效率高
(3)Remoteing主要用于C/S结构项目
(4)不一定要依赖IIS服务器
自已写个了remoting程序运行结果如下:

只是有一个问题,我一直没有调试成功,希望这方面的高手能指点一下:
我想实例化服务器上带参构造函数,然后后台打印出我传的参数值,但总提示应该构造函数不存在
客户端方法:
private static DemoClass CreateInstance()
{
string url = "tcp://10.0.21.233:8501/SimpleRemote/ServerActivated";
object[] activationAtt = { new UrlAttribute(url) };
//DemoClass obj = (DemoClass)Activator.CreateInstance(typeof(DemoClass), new object[]{"chenjie"}, activationAtt);
//return obj;
DemoClass obj = (DemoClass)Activator.CreateInstance(typeof(DemoClass), new object[] { "chenjie" }, activationAtt);
return obj;
}
服务端构造函数:
public class DemoClass : MarshalByRefObject {
private int count = 0;
public DemoClass() {
Console.WriteLine("\n======= DomoClass Constructor =======");
}
public DemoClass(string name)
{
Console.WriteLine("{0}", name);
}
public void ShowCount(string name) {
count++;
Console.WriteLine("{0},the count is {1}.", name, count);
}
// 打印对象所在的应用程序域
public void ShowAppDomain() {
AppDomain currentDomain = AppDomain.CurrentDomain;
Console.WriteLine(currentDomain.FriendlyName);
}
public int GetCount() {
return count;
}
// 示范传值封送
public DemoCount GetNewCount() {
return new DemoCount(count);
}
}
请高手看到后指点一下,本人源码下载地址:http://download.csdn.net/detail/chenjie200280/3604944
浙公网安备 33010602011771号