远程调用从不 returns。可能是远程冲突?

Remoting call never returns. Possibly remoting conflict?

我正在尝试建立对第三方应用程序的 .Net 远程调用。这是我为该连接提供的示例代码(删除了专有名称):

IDictionary props = new ListDictionary();
props["port"] = 0; // have the Remoting system pick a unique listening port (required for callbacks)
props["name"] = string.Empty; // have the Remoting system pick a unique name
BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
_channel = new TcpChannel(props, new BinaryClientFormatterSinkProvider(), serverProv);
ChannelServices.RegisterChannel(_channel, true);

IThirdparty _thirdparty = (IThirdparty)Activator.GetObject(typeof(IThirdparty), "tcp://localhost:9090/Thirdparty.AppIntegration");

//Example API call
_thirdparty.Minimized = !_thirdparty.Minimized;

正常调用此代码时,它会挂起在 _thirdparty.Minimized 并在诊断 window 中输出 SocketException 消息:

No connection could be made because the target machine actively refused it

仅当我关闭第三方应用时才调用 returns。

我检查了 netstat -bano,端口 9090 上唯一的应用程序 运行 是我正在尝试连接的应用程序。

所以我将调用移到了我的应用程序中 Main() 函数的前几行,它工作得很好。问题是,那不是它应该在的地方。

我的应用程序包含许多对不同服务器(不在端口 9090 上)的其他远程调用以及 WCF 服务。我的猜测是这些事情之一正在干扰。

关于我如何弄清楚为什么这个远程调用永远不会 returns 的任何想法?

更新: 我已经确定 SocketException 可能是一个转移注意力的问题,因为这些异常是在它在第 3 方测试应用程序中运行时创建的。此外,看起来它挂起的原因是因为它正在等待一个永远不会获取任何数据的 Socket.Read()。

事实证明,在 .NET 远程处理中,每个 AppDomain 只能有一个 TCPClientChannel。 Activator.GetObject() 使用注册的第一个频道。

阻塞的原因是因为我已经在我的 AppDomain 中设置了 TCPClientChannel。该频道在注册时将安全设置为 false。即

ChannelServices.RegisterChannel(_channel, false);

我尝试与之交谈的服务启用了安全性,因此远程调用将挂起以尝试收听永远不会到来的响应。

解决方案是将我的集成加载到新的 AppDomain 中,以便我可以不同地配置 TCPChannel。