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