Remoting给远程对象属性赋值.....望大家来帮个忙,严究两天未解
snyl 2007-06-14 03:50:26 类
public class wr:MarshalByRefObject
{
public ftpname;
public wr()
{
ftpname="aaa";
}
public string addnew()
{
return ftpname;
}
}
服务端:
TcpServerChannel channel = new TcpServerChannel(8086);
ChannelServices.RegisterChannel(channel,false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Hosts), "hi", WellKnownObjectMode.SingleCall);
客户端:
wrwr= (Hosts)Activator.GetObject(typeof(wr), "tcp://127.0.0.1:8046/hi");
wr.ftpname = "22222";
Response.Write(wr.addnew());
使用这种方法却实可以调用远程对象,但是这种方法调用远程对象的时候就实例化构造函数.所以ftpname的值永远都是默认构造函数的aaa,没有办法在客户端给值.
在网上找了很久发现可以用客户端激活方式,但是总是出错不知道为什么
服务端:
TcpServerChannel channel = new TcpServerChannel(8086);
ChannelServices.RegisterChannel(channel,false);
//客户激活模式
RemotingConfiguration.ApplicationName = "hi";
RemotingConfiguration.RegisterActivatedServiceType(typeof(wr));
客户端:
RemotingConfiguration.RegisterActivatedClientType(typeof(wr), "tcp://127.0.0.1:8086/hi");
wr obj = new wr();
wr.ftpname="2222";
Response.Write(wr.addnew());