简体   繁体   English

.NET 远程处理目标拒绝单个调用 - 返回 socketexception

[英].NET remoting target refusing a single call - returns socketexception

I have an old school .NET remoting app that I needed to extend a little.我有一个老式的 .NET 远程处理应用程序,我需要对其进行一些扩展。 As part of that, I brought it to .NET 4.0.作为其中的一部分,我将它带到了 .NET 4.0。 (was .NET 2.0 before) The interface that is hosted looks like this (之前是 .NET 2.0)托管的界面如下所示

    public interface IRemoteSupportVM
    {
        string runAnOperation(Customer cust, List<CustomRoute> routes);

        string runAnotherOperation(string customer, string routes);

        string runAThirdOperation(List<string> pathsToBeCleaned);

        string writeFile(string path, string filename, int type, byte[] data);

        string readFile(string path, string filename, out byte[] data);

        string deleteFile(string path, string filename);

        long ping();
    }

ping, readFile, writeFile and deleteFile work just fine. ping、readFile、writeFile 和 deleteFile 工作得很好。 When I call runAnOperation/runAnotherOperation/runAThirdOperation, I get an immediate SocketExcepting telling me当我调用 runAnOperation/runAnotherOperation/runAThirdOperation 时,我会立即收到一个 SocketExcepting 告诉我

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond连接尝试失败,因为连接方在一段时间后没有正确响应,或者因为连接的主机没有响应而建立连接失败

Now I now that's a bunch of baloney because all the other calls work just fine, and, the target does get the call and performs its thing.现在我现在这是一堆废话,因为所有其他调用都可以正常工作,并且目标确实收到了调用并执行了它的操作。 But since the client thinks the call failed, everything that comes after calling connect fails too.但是由于客户端认为调用失败,因此调用 connect 之后的一切也失败了。

the solution has a bunch of other remoting interfaces, and as far as I can tell, they all work except these two method calls.该解决方案有一堆其他远程接口,据我所知,除了这两个方法调用之外,它们都可以工作。 Any idea what could trip up the .NET remoting caller?知道什么会绊倒 .NET 远程调用者吗?

@edit: I noted another thing: the run* operations take a while to complete. @edit:我注意到另一件事:run* 操作需要一段时间才能完成。 The other operations return immediately.其他操作立即返回。 As I have the code of both sides of the remoting interface, I set a breakpoint on the implementation of ping(), and now I also get a SocketException when the client calls ping.因为我有remoting接口两边的代码,所以我在ping()的实现上设置了断点,现在客户端调用ping的时候也出现了SocketException。 So it seems to be a timeout I'm not aware of.所以这似乎是我不知道的超时。

Okay, so after a painful trial & error period, I finally found the culprit.好的,经过痛苦的反复试验,我终于找到了罪魁祸首。 It's the timeout of the channel when it gets initialized.它是通道初始化时的超时时间。 That's how it was in the remote side code:这就是远程端代码中的情况:

            IDictionary props = new Hashtable
            {
                ["port"] = config.Port,
                ["timeout"] = config.RemotingTimeout,
            };
            var channel = new TcpChannel(props, clientProv, serverProv);

Now it appears that the timeout property had no effect on .NET 2.0 - there's quite a few google results towards that effect.现在看来 timeout 属性对 .NET 2.0 没有影响 - 有相当多的谷歌结果对这种影响。 However, in .NET 4.0 it suddenly seems to take.但是,在 .NET 4.0 中,它似乎突然出现了。 Every remoting call is wrapped IAsync* Begin/EnvInvoke to ensure a result after the desired timeout (even if that result is that the server didn't provide a result in time).每个远程调用都包装在 IAsync* Begin/EnvInvoke 中,以确保在所需的超时后得到结果(即使该结果是服务器没有及时提供结果)。 So either nobody every noticed that timeout had no meaning or the execution wrapper was put in place for exactly that reason (the software was started 15 years ago.. so who knows).因此,要么没人注意到超时没有意义,要么正是出于这个原因才安装了执行包装器(该软件是在 15 年前启动的……所以谁知道呢)。

As config.RemotingTimeout was 70, a call had 70 miliseconds to complete or I'd get the SocketException.由于 config.RemotingTimeout 为 70,调用需要 70 毫秒才能完成,否则我会得到 SocketException。 When I converted the 70 seconds (that I was expecting) to milliseconds ( so timeout = 70000), things suddenly started working the way I expected them to.当我将 70 秒(我期望的)转换为毫秒(所以超时 = 70000)时,事情突然开始按照我期望的方式工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM