快精灵印艺坊 您身边的文印专家
广州名片 深圳名片 会员卡 贵宾卡 印刷 设计教程
产品展示 在线订购 会员中心 产品模板 设计指南 在线编辑
 首页 名片设计   CorelDRAW   Illustrator   AuotoCAD   Painter   其他软件   Photoshop   Fireworks   Flash  

 » 彩色名片
 » PVC卡
 » 彩色磁性卡
 » 彩页/画册
 » 个性印务
 » 彩色不干胶
 » 明信片
   » 明信片
   » 彩色书签
   » 门挂
 » 其他产品与服务
   » 创业锦囊
   » 办公用品
     » 信封、信纸
     » 便签纸、斜面纸砖
     » 无碳复印纸
   » 海报
   » 大篇幅印刷
     » KT板
     » 海报
     » 横幅

.net remoting范例

 

1:创建一个工程文件,是SERVER端的。

using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

namespace HelloServer
{
 /// <summary>
 /// Class1 的摘要说明。
 /// </summary>
 class HS
 {
  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [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
{
 /// <summary>
 /// Class1 的摘要说明。
 /// </summary>
 class HC
 {
  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [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(\"haha\"));
     Console.ReadLine();
    }
   }
   catch (Exception ex)
   {
    Console.WriteLine(ex.Message);
    Console.WriteLine(ex.Source);
    Console.ReadLine();
   }   
  }
 }
}

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

呵呵。。。完毕。。





返回类别: 教程
上一教程: 使用.NET生成Excel文件
下一教程: 常用的读写ini文件的类

您可以阅读与".net remoting范例"相关的教程:
· .NET Remoting 实现分布式数据库查询
· .NET Remoting 实现分布式数据库查询
· 微软的远程处理框架.NET Remoting - 1
· 微软的远程处理框架.NET Remoting - 2
· .NET 下的remoting使用。(TCP通道)
    微笑服务 优质保证 索取样品