1.只能通过客户端激活的才能用有参的构造函数
就是在配置文件里用<activated>
2.可以实现,你可以试下代理与事件,具体文章可以在www.csdn.net里搜索remoting来看
微软社区里也有这方面的文章.
3.在配置文件里用<activated>
4.gz,没怎么看懂
就是在配置文件里用<activated>
2.可以实现,你可以试下代理与事件,具体文章可以在www.csdn.net里搜索remoting来看
微软社区里也有这方面的文章.
3.在配置文件里用<activated>
4.gz,没怎么看懂
using System.Collections ;
using PersonInfoDLL;namespace ServerDLL
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
public class Server:System.MarshalByRefObject
{
private ArrayList personList;
//自定义人员信息类
private PersonInfoDLL.PersonInfo personInfo; public Server()
{
//
// TODO: 在此处添加构造函数逻辑
//
personList = new ArrayList ();
} //注册用户
public void Register(string name,string passWord)
{
personInfo = new PersonInfo (name,passWord);
personList.Add (personInfo);
} public ArrayList GetDataList
{
get
{
return personList;
}
} }
}using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime ;
using System.Runtime .Remoting ;
using System.Runtime .Remoting .Channels ;
using System.Runtime .Remoting .Channels .Tcp ;
using ServerDLL;
using PersonInfoDLL;namespace OicqClient
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class clientForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBoxName;
private System.Windows.Forms.TextBox textBoxPwd;
private System.Windows.Forms.Button buttonRegister;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; private ServerDLL.Server theServer;
private TcpChannel clientChannel;
public clientForm()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
// clientChannel = new TcpChannel (0);
ChannelServices.RegisterChannel (clientChannel); try
{
theServer = (Server)Activator.GetObject (typeof(Server),"tcp://localhost:8090/PublishSubscribe");
}
catch(Exception ex)
{
MessageBox.Show ("zheli出现异常"+ex.Message );
} } /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.textBoxName = new System.Windows.Forms.TextBox();
this.textBoxPwd = new System.Windows.Forms.TextBox();
this.buttonRegister = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(24, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(48, 23);
this.label1.TabIndex = 0;
this.label1.Text = "姓名";
//
// label2
//
this.label2.Location = new System.Drawing.Point(24, 80);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(48, 23);
this.label2.TabIndex = 1;
this.label2.Text = "密码";
//
// textBoxName
//
this.textBoxName.Location = new System.Drawing.Point(88, 32);
this.textBoxName.Name = "textBoxName";
this.textBoxName.TabIndex = 2;
this.textBoxName.Text = "";
//
// textBoxPwd
//
this.textBoxPwd.Location = new System.Drawing.Point(88, 80);
this.textBoxPwd.Name = "textBoxPwd";
this.textBoxPwd.TabIndex = 3;
this.textBoxPwd.Text = "";
//
// buttonRegister
//
this.buttonRegister.Location = new System.Drawing.Point(88, 152);
this.buttonRegister.Name = "buttonRegister";
this.buttonRegister.TabIndex = 4;
this.buttonRegister.Text = "注册";
this.buttonRegister.Click += new System.EventHandler(this.buttonRegister_Click);
//
// clientForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.buttonRegister,
this.textBoxPwd,
this.textBoxName,
this.label2,
this.label1});
this.Name = "clientForm";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new clientForm());
} private void buttonRegister_Click(object sender, System.EventArgs e)
{
if(theServer!=null)
{
theServer.Register (textBoxName.Text ,textBoxPwd.Text);
}
}
}
}
2. 普通.NET的时间模型在Remoting环境下同样适用(delegate/event),但要注意这种回调对于防火墙后面的客户无效。
3. .NET有自带的例子。
4. 简单情况下(构造函数参数里面没有ref/out),只要把这些参数按顺序放到一个Object[]里面就可以了。