Webcast.NET Remoting学习笔记(1)第一个remoting程序
2007-02-02 17:24
495 查看
最近开始学习分布式程序设计,在网上下了msdn的视频教程,边看边学边记笔记,坚持把教程全部学习一遍。
先以一个简单的例子开始.NET Remoting的学习。
开发Remoting有三步:
1、创建远程对象
2、创建一个应用程序作为宿主,接受客户端的请求。
3、创建一个客户端调用远程对象。
下面开始第一步:
在解决方案中添加类库项目General
using System;
using System.Collections.Generic;
using System.Text;
namespace RemotingSamples
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;
namespace RemotingSamples
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;
using System.IO;
namespace RemotingSamples
public class Client
public static void Main(string[] args)
//使用TCP通道得到远程对象
TcpChannel chan1 = new TcpChannel();
ChannelServices.RegisterChannel(chan1);
HelloServer obj1 = (HelloServer)Activator.GetObject(
typeof(RemotingSamples.HelloServer),
"tcp://localhost:8085/SayHello");
if (obj1 == null)
System.Console.WriteLine(
"Could not locate TCP server");
}
//使用HTTP通道得到远程对象
HttpChannel chan2 = new HttpChannel();
ChannelServices.RegisterChannel(chan2);
HelloServer obj2 = (HelloServer)Activator.GetObject(
typeof(RemotingSamples.HelloServer),
"http://localhost:8086/SayHello");
if (obj2 == null)
System.Console.WriteLine(
"Could not locate HTTP server");
}
Console.WriteLine(
"Client1 TCP HelloMethod {0}",
obj1.HelloMethod("服务器收到请回答1"));
Console.WriteLine(
"Client2 HTTP HelloMethod {0}",
obj2.HelloMethod("服务器收到请回答2"));
Console.ReadLine();
}
}
}然后开始执行(不调试)server,之后对client执行“启动新实例”可以看到结果
先以一个简单的例子开始.NET Remoting的学习。
开发Remoting有三步:
1、创建远程对象
2、创建一个应用程序作为宿主,接受客户端的请求。
3、创建一个客户端调用远程对象。
下面开始第一步:
在解决方案中添加类库项目General
using System;
using System.Collections.Generic;
using System.Text;
namespace RemotingSamples
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;
namespace RemotingSamples
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;
using System.IO;
namespace RemotingSamples
public class Client
public static void Main(string[] args)
//使用TCP通道得到远程对象
TcpChannel chan1 = new TcpChannel();
ChannelServices.RegisterChannel(chan1);
HelloServer obj1 = (HelloServer)Activator.GetObject(
typeof(RemotingSamples.HelloServer),
"tcp://localhost:8085/SayHello");
if (obj1 == null)
System.Console.WriteLine(
"Could not locate TCP server");
}
//使用HTTP通道得到远程对象
HttpChannel chan2 = new HttpChannel();
ChannelServices.RegisterChannel(chan2);
HelloServer obj2 = (HelloServer)Activator.GetObject(
typeof(RemotingSamples.HelloServer),
"http://localhost:8086/SayHello");
if (obj2 == null)
System.Console.WriteLine(
"Could not locate HTTP server");
}
Console.WriteLine(
"Client1 TCP HelloMethod {0}",
obj1.HelloMethod("服务器收到请回答1"));
Console.WriteLine(
"Client2 HTTP HelloMethod {0}",
obj2.HelloMethod("服务器收到请回答2"));
Console.ReadLine();
}
}
}然后开始执行(不调试)server,之后对client执行“启动新实例”可以看到结果
相关文章推荐
- 用jQuery写的第一个程序,用到了append函数,是一次web上机作用
- swift之第一个IOS程序(浏览web页面)
- 第一个Spring Boot Web程序
- [Ruby on Rails系列]3、初试Rails:使用Rails开发第一个Web程序
- 第一个web程序(ServletRequest , ServletResponse)
- Windows Azure入门教学系列 (一): 创建第一个WebRole程序
- 第一个web程序总结
- 《Go语言入门》第一个Go语言Web程序——简单的Web服务器
- 使用MyEclipse开发第一个Web程序
- Servlet入门(第一个Servlet的Web程序)
- 【JavaWeb开发(二)】第一个jsp程序以及web.xml分析
- 4. 尚硅谷_佟刚_JavaWEB_第一个 Servlet 程序.wmv
- 第一个高德地图的Web程序
- Python Web 开发学习 - 第一个Python程序
- 我做的第一个web安装部署项目---全国计算机等级考试网上报名缴费程序
- python 第一个web程序
- Windows Azure入门教学系列 (二):部署第一个Web Role程序
- [web开发] 如何在Mac OS上安装Apache Tomcat并运行你的第一个Servlet程序
- React+webpack构建你的第一个程序
- python使用web.py建立第一个hello world程序