服务端是怎么向类库传值
我用服务端向类库传值(调用类库的方法),客户端取出来是空的
我把值直接赋在类库的变量中,客户端可以正常取到
你说的那种可以讲明白点吗
[此贴子已经被作者于2007-10-25 16:29:35编辑过]
//这是dll
using System;
public class HelloServer : MarshalByRefObject
{
public HelloServer()
{
}
private string scp1 = "";
private string scp2 = "";
private string scp3 = "";
private string scp4 = "";
private string scp5 = "";
/// <summary>
/// 服务端调用
/// </summary>
/// <param name="flag"></param>
public void scp11(string flag)
{
scp1 = flag;
}
public void scp22(string flag)
{
scp2 = flag;
}
public void scp33(string flag)
{
scp3 = flag;
}
public void scp44(string flag)
{
scp4 = flag;
}
public void scp55(string flag)
{
scp5 = flag;
}
/// <summary>
/// 客户端调用
/// </summary>
/// <returns></returns>
public string ccp1()
{
string cp1 = "";
cp1 = scp1;
return cp1;
}
public string ccp2()
{
string cp2 = "";
cp2 = scp2;
return cp2;
}
public string ccp3()
{
string cp3 = "";
cp3 = scp3;
return cp3;
}
public string ccp4()
{
string cp4 = "";
cp4 = scp4;
return cp4;
}
public string ccp5()
{
string cp5 = "";
cp5 = scp5;
return cp5;
}
}
//服务端
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace server
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
ChannelServices.RegisterChannel(new TcpChannel(8082));
}
private void button1_Click(object sender, EventArgs e)
{
RemotingConfiguration.RegisterActivatedServiceType(typeof(HelloServer));
HelloServer server = new HelloServer();
server.scp11(this.textBox1.Text);
}
}
}
//客户端
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace client
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
ChannelServices.RegisterChannel(new TcpChannel());
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}
// 创建 激活 客户端类型 实体.
ActivatedClientTypeEntry myActivatedClientTypeEntry =
new ActivatedClientTypeEntry(typeof(HelloServer),
"tcp://localhost:8082");
// 通过注册客户端类型激活服务端
RemotingConfiguration.RegisterActivatedClientType(
myActivatedClientTypeEntry);
}
private void button1_Click(object sender, EventArgs e)
{
try
{
// 实例化客户端对象
HelloServer server = new HelloServer();
// 在本地检查与服务端的连接.
if (server == null)
{
this.label1.Text = ("连接失败!");
}
else
{
this.label1.Text = server.ccp1();
}
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}
}
}
}