namespace ClassRef{ /// <summary> /// 代理 /// </summary> public class Proxy: MarshalByRefObject { public void SayHello(Consignor consignor) { Console.WriteLine("正在执行委托任务。。。"); consignor.SayHello(); Console.WriteLine("执行完成"); } }}
namespace ClassRef{ /// <summary> /// 委托人 /// </summary> public class Consignor : MarshalByRefObject { public void SayHello() { Console.WriteLine("Hello"); } }}
namespace ServerForCode{ class Program { static void Main(string[] args) { //设置安全限制 BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider(); provider.TypeFilterLevel = TypeFilterLevel.Full; IDictionary props = new Hashtable(); props["port"] = 8085; //注册信道 TcpChannel chan = new TcpChannel(props, null, provider); ChannelServices.RegisterChannel(chan, true); //设置服务器提供的注册类型Proxy RemotingConfiguration.RegisterWellKnownServiceType( typeof(Proxy), "RemoteTestRef", WellKnownObjectMode.SingleCall); Console.WriteLine("Press <ENTER> to exit..."); Console.ReadLine(); } }}
namespace ClientForCode{ class Program { static void Main(string[] args) { //注册信道 TcpChannel chan = new TcpChannel(8087); ChannelServices.RegisterChannel(chan, true); //将Proxy注册为可在服务器激活的类型 RemotingConfiguration.RegisterWellKnownClientType(typeof(Proxy), "tcp://localhost:8085/RemoteTestRef"); //声明服务器对象 Proxy proxy = new Proxy(); //声明以引用方式传到服务器的对象 Consignor consignor = new Consignor(); proxy.SayHello(consignor); Console.WriteLine("Press <ENTER> to exit..."); Console.ReadLine(); } }}
求助,客服端这边运行总是一次成功,一次失败的。异常信息是“写操作失败,请参见内部异常。”。是哪里代码写错了。
- 2 回答
- 0 关注
- 513 浏览
添加回答
举报
0/150
提交
取消

