当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > .net remoting范例

ASP.NET
asp.net图片加水印
Asp.Net中页面运行时动态载入的UserControl内元素的事
ASP.NET底层架构探索之再谈.NET运行时(二)
借助封装类实现线程调用带参方法
面向对象设计思想(C#)
asp.net URL重写(URLRewriter) 简化版
GUID在.net里的使用,就用System.Guid结构
不要忽略c#中的using和as操作符
C#中ref和out的使用小结
C#的Web XML编程
asp.net2.0下 如何实现服务器端压缩包自解压
javascript如何调用C#后台代码中的过程 和ASP.NET调用
在ASP.NET中自动给URL加上超链接
ASP.NET 中处理页面“回退”的方法
ASP.NET的四种错误机制
asp.net跳转页面的三种方法比较
ASP.NET2.0中将GridView导出到Excel文件中
ASP.NET 2.0中GridView无限层复杂表头的实现
ASP.NET 2.0 中动态添加 GridView 模板列
十天学会ASP.net之第一天

ASP.NET 中的 .net remoting范例


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 57 ::
收藏到网摘: n/a


1:创建一个工程文件,是SERVER端的。
using System;using System.Runtime.Remoting;using System.Runtime.Remoting.Channels;using System.Runtime.Remoting.Channels.Tcp;
namespace HelloServer{ /// /// Class1 的摘要说明。 /// class HS { /// /// 应用程序的主入口点。 /// [STAThread] static void Main(string[] args) { // // TODO: 在此处添加代码以启动应用程序 // try { TcpServerChannel channel =new TcpServerChannel(8086); ChannelServices.RegisterChannel(channel); Type t=typeof(RemoteHello.Hello); RemotingConfiguration.RegisterWellKnownServiceType(t,"hi",WellKnownObjectMode.SingleCall); Console.WriteLine("hit to exit"); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.Source); Console.ReadLine(); } } }}
2:创建一个工程文件是client端的:
using System;using System.Runtime.Remoting.Channels;using System.Runtime.Remoting.Channels.Tcp;
namespace HelloClient{ /// /// Class1 的摘要说明。 /// class HC { /// /// 应用程序的主入口点。 /// [STAThread] static void Main(string[] args) { // // TODO: 在此处添加代码以启动应用程序 // try { TcpClientChannel tc=new TcpClientChannel(); ChannelServices.RegisterChannel(tc); RemoteHello.Hello obj = (RemoteHello.Hello)Activator.GetObject(typeof(RemoteHello.Hello),"tcp://10.10.10.111:8086/hi"); if(obj==null) { Console.WriteLine("FAILED!"); return; } for(int i=0;i<2;i++) { Console.WriteLine(obj.Greeting( )); Console.ReadLine(); } } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.Source); Console.ReadLine(); } } }}

3:在编译完以后,先运行server.exe文件,然后再运行client.exe文件,,,这样在MS-DOS下面,就可以看到,client掉用server。。。呵呵。。。完毕。。