您的位置:首页 > 移动开发

WindowsFormsApplicationBase 遇 Remoting 报 远程主机强迫关闭了一个现有的连接

2016-09-21 17:27 721 查看
近日软件增加了通过远程对象调用远程对象的方法功能,在我的开发环境很顺利,按部就班完成了调用,测试也顺利通过。但发布到用户电脑上就出现了问题,不是所有电脑都有问题,个别电脑出现了如下错误:远程主机强迫关闭了一个现有的连接,把堆栈输出:

在 System.Net.Security.NegoState.ProcessAuthentication(LazyAsyncResult lazyResult)

....

Exception rethrown at [0]: 

   在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)

百思不得其解啊,最开始并没想到是WindowsFormsApplicationBase引起的。直到搜索到了老外的一个问答才知道解决办法:

那就是 "priority"属性的作怪,把该属性设置为10就可以了。可能原因是程序默认权限比较低,创建信道时失去了与远程连接的权限,现在把权限提升后,运行正常。

                BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();

                provider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

                BinaryClientFormatterSinkProvider clientprovider = new BinaryClientFormatterSinkProvider();

                IDictionary props = new Hashtable();

                props["port"] = 0;

                props["name"] = "client";

                props["priority"] = "10";

                TcpChannel clientChanel = new TcpChannel(props, clientprovider, provider);

                ChannelServices.RegisterChannel(clientChanel, false);

--------------------------------------------------------------------------以下是网络上搜索到的结果--------------------------

Hi,

The TcpChannel created internally is given the default priority. I create 

our additional channel with a higher priority, which seems to solve the 

problem. I'm not sure this is a proper fix, but it seems to work.

System.Collections.IDictionary properties = new 

System.Collections.Hashtable();

properties["name"] = string.Empty;

properties["priority"] = "10";
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐