namespace ClassRef{??? /// <summary>??? /// 代理??? /// </summary>?? public? class Proxy: MarshalByRefObject?? {?????? public void SayHello(Consignor consignor)?????? {?????????? Console.WriteLine("正在執(zhí)行委托任務。。。");?????????? consignor.SayHello();?????????? Console.WriteLine("執(zhí)行完成");?????? }???????? ??? }}
?
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 關注
- 466 瀏覽
添加回答
舉報
0/150
提交
取消