简体   繁体   English

WCF 使用 nettcpbinding 时通信异常

[英]WCF communicationexception when using nettcpbinding

We have a self-hosted WCF service based on a NetTCPBinding.我们有一个基于 NetTCPBinding 的自托管 WCF 服务。 Since a few weeks, a communicationexception randomly appears after 4000-5000 requests, and afterwards all requests are working again fine.几周后,在 4000-5000 个请求后随机出现通信异常,之后所有请求都可以正常工作。 Also, if I repeat the same failed request, the request works too.此外,如果我重复相同的失败请求,该请求也会起作用。 This misbehavior appears at one customer-installation, for 100 others the WCF-Service works quite fine with the same implementation and NetTCPBinding.这种不当行为出现在一个客户安装中,另外 100 个 WCF 服务在相同的实现和 NetTCPBinding 下工作得很好。 From our side there was no update, the problems started over night.从我们这边看,没有更新,问题在一夜之间就开始了。 I activated Service trace viewer tool - however i could not find anything that gives rise to this problem.我激活了服务跟踪查看器工具 - 但是我找不到导致此问题的任何内容。 So i checked windows updates: I have seen that there was (amongst others) following Windows Update https://support.microsoft.com/de-at/help/4538158/kb4538158 which indicates that Microsoft "solved" an issue for WCFNetTCP binding. So i checked windows updates: I have seen that there was (amongst others) following Windows Update https://support.microsoft.com/de-at/help/4538158/kb4538158 which indicates that Microsoft "solved" an issue for WCFNetTCP binding . However, it seems that they have broken something here:-)但是,他们似乎在这里破坏了一些东西:-)

So I changed the NetTCPBinding to BasicHTTPBinding, and this exception does not appear anymore.于是我把NetTCPBinding改成了BasicHTTPBinding,这个异常就不再出现了。 However, we would like to use NetTCPBinding instead of BasicHTTPBinding... Has anybody else this problem?但是,我们想使用 NetTCPBinding 而不是 BasicHTTPBinding... 还有其他人有这个问题吗?

The communication error/timeout error typically is caused by that the client proxy is not properly closed.通信错误/超时错误通常是由于客户端代理未正确关闭引起的。 I suggest you put the client proxy/service channel in a Using statement.我建议您将客户端代理/服务通道放在 Using 语句中。

using (ServiceReference1.ServiceClient client=new ServiceClient())
            {
                var result = client.Test();
                Console.WriteLine(result);
            }

Besides, please try to set up the below properties.此外,请尝试设置以下属性。

NetTcpBinding binding = new NetTcpBinding();
binding.MaxBufferSize = Int32.MaxValue;
binding.MaxBufferPoolSize = Int32.MaxValue;
binding.SendTimeout = new TimeSpan(0, 10, 0);
binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
binding.OpenTimeout = new TimeSpan(0, 10, 0);

Feel free to let me know If the problem still exists.如果问题仍然存在,请随时告诉我。

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

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