国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 永平县| 隆回县| 阳谷县| 合川市| 东乌| 定陶县| 乌审旗| 新乐市| 隆尧县| 泰安市| 万载县| 社旗县| 黄平县| 竹山县| 科技| 南涧| 万盛区| 景德镇市| 穆棱市| 江孜县| 怀柔区| 利辛县| 澄江县| 黑龙江省| 盐津县| 长寿区| 慈利县| 茂名市| 马公市| 长武县| 广东省| 房山区| 始兴县| 天津市| 宾川县| 西青区| 中西区| 台中市| 台中市| 沙湾县| 桐梓县|