All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
C#应用:用Split()方法提取字符_[Asp.Net教程]
ASP.NET实现站点的RSS功能_[Asp.Net教程]
GridView属性、方法和事件
delphi目录的创建以及更改当前目录
.NET3.5正统分页控件来了(ListView和DataPager)_[Asp.Net教程]
ADO.NET中的sql连接_[Asp.Net教程]
单击GridView某行获取该行某列内容并显示_[Asp.Net教程]
C#,4.0语言将出现重大改变,带来一段Code,Preview_[Asp.Net教程]
PHP正式进入IIS微软与Zend携手推动PHP语言发展_php资料_编程技术
ASP.NET,2.0配合MasterPage的优化CSS_[Asp.Net教程]
Reading number is top 10 pictures
人美胸美腿更美1
美女浴室写真2
乳娘帕梅拉安德森4
陪睡门马睿菈自曝写真 称首拍大尺度照片1
NeedWallpaper4
Flow chart of breast implants
采访美女孙菲菲
人美胸美腿更美4
The hot big eye big breast beauty2
Sora aoi possession photo1
Download software ranking
Visual C++界面编程技术
SQL2000 For 4IN1
Unix video tutorial8
Unix video tutorial14
Unix video tutorial6
Boxer vs Yellow5
Photoshop 8.0图象编辑软件
Boxer vs Yellow4
Popkart Cracked versions Mobile phone games
The Bermuda triangle2
qq published in(发表于) 2014/7/9 1:35:51 Edit(编辑)
ASP.NET Remoting体系结构(八)

ASP.NET Remoting体系结构(八)

ASP.NET Remoting体系结构(八): 构建远程类对象

构建远程类对象

(1)在VS2005中新建一个项目,选择Windows窗体模板,将窗体的输出类型设置为类库并命名为RemotingClass,同时将应用程序的输出类型改为类库,如图1所示。

(2)将窗体类改为FarClass并在窗体代码文件中加入如下代码:

namespace RemotingClass

{

public partial class FarClass : Form

{

public static int i;

public FarClass()

{

InitializeComponent();

}

public int GetTime()

{

StreamWriter sw = new StreamWriter("hb.txt", True);

sw.WriteLine("远程类对象被第" + i + "次调用" + DateTime.Now.ToString());

sw.Close();

i++;

MessageBox.Show("远程类在服务器端对象被"+i+"次调用"+DateTime.Now.ToString());

return i;

}

}

}

如果是用户编写的远程类,则必须继承System.MarshalByRefObject。因为Form类已经继承于System.MarshalByRefObject,所以本例没有继承。代码如下:

public static int i;

制作一个计数器,来记录远程类对象被调用了几次,代码如下:

StreamWriter sw = new StreamWriter("hb.txt", True);

sw.WriteLine("远程类对象被第" + i + "次调用" + DateTime.Now.ToString());

sw.Close();

StreamWriter是一个专门用于文件写入的类,这里用来对远程类的调用做一个记录以便体会远程调用的这种体系。StreamWriter("hb.txt", True) 构造函数中的第一个参数为文件名,第二个参数如果为True,则表示在文件末尾追加;fasle表示写入的内容要覆盖以前内容。sw.WriteLine()函数是用来将一个字符串写入一行。DateTime.Now.ToString()是系统当前时间。最后将Stream Writer对象的实例关闭。代码如下:

MessageBox.Show("远程类在服务器端对象被"+i+"次调用"+DateTime.Now.ToString());

在弹出的MessageBox中,在服务端看到客户端调用远程类,每调用一次就可以看到服务端弹出的窗体以显示远程类的调用。

(3)编译程序生成类库。

完整程序代码如下:

★ ★★★★Program.cs主程序文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.Windows.Forms;

namespace RemotingClass

{

static class Program

{

///



/// 应用程序的主入口点。

///


[STAThread]

static void Main()

{

Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

Application.Run(new FarClass());

}

}

}

★ ★★★★RemotingClass.cs窗体代码文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.IO;

namespace RemotingClass

{

public partial class FarClass : Form

{

public static int i;

public FarClass()

{

InitializeComponent();

}

public int GetTime()

{

StreamWriter sw = new StreamWriter("hb.txt", true);

sw.WriteLine("远程类对象被第" +i + "次调用" + DateTime.Now.ToString());

sw.Close();

i++;

MessageBox.Show("远程类在服务器端对象被"+i+"次调用"+DateTime.Now.ToString());

return i;

}

}

}

★ ★★★★RemotingClass.designer.cs窗体设计文件完整程序代码★★★★★

namespace RemotingClass

{

partial class FarClass

{

///

/// 必需的设计器变量。


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.