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

ASP.NET
现有的Web打印控制技术的方案
一段实现DataGrid的“编辑”、“取消”功能脚本
.Net中将图片数据保存到XML文档
如何在C#的WinForm中制作饼状图和柱状图
在RichTextBox控件加入图片
C#写的数据库操作类!
使用响应文件编译C#源文件
在 Visual Basic .NET 中实现后台进程(一)
在 Visual Basic .NET 中实现后台进程(二)
在 Visual Basic .NET 中实现后台进程(三)
用C#写vs插件中的一些Tip
C++编程人员容易犯的10个C#错
在Repeater中嵌套使用Repeater
Project级别的权限控制
一个FTP客户端的C#代码
用c#写的smtp邮件发送类
挤压造型Extrusion的节点说明和应用实例
.net 里面 protected private 的变量也可以访问
signlog 登陆实现
利用自定义事件实现不同窗体间的通讯 -- C#篇

ASP.NET 中的 .net remoting范例


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 110 ::
收藏到网摘: 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。。。呵呵。。。完毕。。