为了账号安全,请及时绑定邮箱和手机立即绑定

TcpChannel 使用 写操作失败,请参见内部异常

TcpChannel 使用 写操作失败,请参见内部异常

三国纷争 2018-12-07 13:56:17
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 回答

?
qq_花开花谢_0

TA贡献1835条经验 获得超7个赞

将你的代码做了下整理分成三个程序集,Client ,Server ,Contract 三部分,再把解决方案设置成多启动项目,运行了几次,没出现问题, 不知道你是怎么架设项目的。主要有两点、服务器端要确保启动、端口可用、通信完后要关闭连接。

查看完整回答
反对 回复 2019-01-21
?
慕桂英546537

TA贡献1848条经验 获得超10个赞

你的客户端没有关闭TcpChannel吗?

把你的客户端异常的StackTrace贴出来。

查看完整回答
反对 回复 2019-01-21
  • 2 回答
  • 0 关注
  • 513 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号