建立C#类库项目DLL
实现代码:
using System;
namespace DLL
{
 /// 
 /// test 的摘要说明。
 /// 
 [System.Serializable]
 public class test
 {
  public test()
  {
   //
   // TODO: 在此处添加构造函数逻辑
   //
  }
  public string Time
  {
   get
   {
    return DateTime.Now.ToString();
   }
  }
 }
}
using System;
using System.IO;
namespace DLL
{
 /// 
 /// api 的摘要说明。
 /// 
 public class api : System.MarshalByRefObject
 {
  public api()
  {
   //
   // TODO: 在此处添加构造函数逻辑
   //
  }
  public string GetTime()
  {
   return new test().Time;
  }
  public string[] GetDirectories(string path)
  {
   return Directory.GetDirectories(path);
  }
  public string[] GetFiles(string path)
  {
   return Directory.GetFiles(path);
  }
 }
}
添加C#windows应用程序项目server
实现代码:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using DLL;
namespace Server
{
 /// 
 /// Form1 的摘要说明。
 /// 
 public class Form1 : System.Windows.Forms.Form
 {
  /// 
  /// 必需的设计器变量。
  /// 
  private System.ComponentModel.Container components = null;
  public Form1()
  {
   //
   // Windows 窗体设计器支持所必需的
   //
   InitializeComponent();
   //
   // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
   //
  }
  /// 
  /// 清理所有正在使用的资源。
  /// 
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null) 
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }
  #region Windows 窗体设计器生成的代码
  /// 
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// 
  private void InitializeComponent()
  {
   // 
   // Form1
   // 
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(208, 150);
   this.Name = "Form1";
   this.Text = "Form1";
   this.Load += new System.EventHandler(this.Form1_Load);
  }
  #endregion
  /// 
  /// 应用程序的主入口点。
  /// 
  [STAThread]
  static void Main() 
  {
   Application.Run(new Form1());
  }
  private void Form1_Load(object sender, System.EventArgs e)
  {
   TcpChannel chan = new TcpChannel(7777);
   ChannelServices.RegisterChannel(chan);
   RemotingConfiguration.RegisterWellKnownServiceType(
    Type.GetType("DLL.api, Dll"),
    "test",
    WellKnownObjectMode.SingleCall);
  }
 }
}
添加c#windows应用程序项目client
global.cs代码:
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using DLL;
namespace Client
{
 /// 
 /// Global 的摘要说明。
 /// 
 public class Global
 {
  public Global()
  {
   //
   // TODO: 在此处添加构造函数逻辑
   //
  }
  public static DLL.api api
  {
   get
   {
    return (DLL.api)Activator.GetObject(typeof(DLL.api), "tcp://"+ Config.Host + ":" + Config.Port + "/test");
   }
  }
 }
}
主窗体关键代码:
  [STAThread]
  static void Main() 
  {
   Application.Run(new Form1());
   ChannelServices.RegisterChannel(new TcpChannel());
  }
  private void Form1_Load(object sender, System.EventArgs e)
  {
   string[] files = Global.api.GetFiles(@"c:\");//取得服务器C盘文件
  }
参考文献:http://support.microsoft.com/default.aspx?scid=kb;zh-cn;307546

