国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

使用 Visual C# .NET 按值將對象封送到遠程服務(wù)器

2024-07-10 13:07:22
字體:
供稿:網(wǎng)友

建立c#類庫項目dll

實現(xiàn)代碼:

using system;

namespace dll
{
 /// <summary>
 /// test 的摘要說明。
 /// </summary>
 [system.serializable]
 public class test
 {
  public test()
  {
   //
   // todo: 在此處添加構(gòu)造函數(shù)邏輯
   //
  }

  public string time
  {
   get
   {
    return datetime.now.tostring();
   }
  }
 }
}

using system;
using system.io;

namespace dll
{
 /// <summary>
 /// api 的摘要說明。
 /// </summary>
 public class api : system.marshalbyrefobject
 {
  public api()
  {
   //
   // todo: 在此處添加構(gòu)造函數(shù)邏輯
   //
  }

  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應(yīng)用程序項目server

實現(xiàn)代碼:

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
{
 /// <summary>
 /// form1 的摘要說明。
 /// </summary>
 public class form1 : system.windows.forms.form
 {
  /// <summary>
  /// 必需的設(shè)計器變量。
  /// </summary>
  private system.componentmodel.container components = null;

  public form1()
  {
   //
   // windows 窗體設(shè)計器支持所必需的
   //
   initializecomponent();

   //
   // todo: 在 initializecomponent 調(diào)用后添加任何構(gòu)造函數(shù)代碼
   //
  }

  /// <summary>
  /// 清理所有正在使用的資源。
  /// </summary>
  protected override void dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.dispose();
    }
   }
   base.dispose( disposing );
  }

  #region windows 窗體設(shè)計器生成的代碼
  /// <summary>
  /// 設(shè)計器支持所需的方法 - 不要使用代碼編輯器修改
  /// 此方法的內(nèi)容。
  /// </summary>
  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

  /// <summary>
  /// 應(yīng)用程序的主入口點。
  /// </summary>
  [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應(yīng)用程序項目client

global.cs代碼:

using system;
using system.runtime.remoting;
using system.runtime.remoting.channels;
using system.runtime.remoting.channels.tcp;

using dll;
namespace client
{
 /// <summary>
 /// global 的摘要說明。
 /// </summary>
 public class global
 {
  public global()
  {
   //
   // todo: 在此處添加構(gòu)造函數(shù)邏輯
   //
  }
  public static dll.api api
  {
   get
   {
    return (dll.api)activator.getobject(typeof(dll.api), "tcp://"+ config.host + ":" + config.port + "/test");
   }
  }
 }
}

主窗體關(guān)鍵代碼:

  [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:/");//取得服務(wù)器c盤文件
  }
參考文獻:http://support.microsoft.com/default.aspx?scid=kb;zh-cn;307546

商業(yè)源碼熱門下載www.html.org.cn

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 江达县| 文山县| 健康| 盐山县| 桓台县| 崇左市| 广州市| 武平县| 田阳县| 义乌市| 斗六市| 沽源县| 张家港市| 岑溪市| 台北县| 舒兰市| 宜兴市| 海宁市| 霍城县| 西乡县| 辰溪县| 江都市| 香河县| 来凤县| 志丹县| 奉化市| 团风县| 阿巴嘎旗| 岳池县| 天全县| 万州区| 陆河县| 叙永县| 姚安县| 盈江县| 文登市| 澄城县| 清水河县| 剑阁县| 永年县| 即墨市|