编写 Form1.cs 如代码 13.6 所示。
代码 13.6 Remoting 客户端程序:Form1.cs
using System;
using System.Windows.Forms;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using NetRmClass;
namespace NetRmClient
{
public partial class Form1 : Form
{
//声明 TcpClientChannel 类型的字段 channelc
TcpClientChannel channelc;
//声明 RmObj 类型的字段 obj
RmObj obj;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//创建 TcpClientChannel 对象,引用为 channelc
channelc = new TcpClientChannel();
//将 channels 注册到信道服务
ChannelServices.RegisterChannel(channelc, false);
//创建远程对象
obj = (RmObj)Activator.GetObject(typeof(RmObj),
"tcp://localhost:3000/MyUri");
}
private void button1_Click(object sender, EventArgs e)
{
string MyName = textBox1.Text;
//调用远程对象的 Diss 方法,并传递用户输入值
obj.Diss(MyName);
//调用远程对象的 Disc 方法,返回值赋值给 textBox1
“
控件的 Text”属性
this.textBox1.Text = obj.Disc();
}
}