WCF:System.Net.SocketException - 每个套接字地址(协议/网络地址/端口)的一个用法通常被允许 [英] WCF: System.Net.SocketException - Only one usage of each socket address (protocol/network address/port) is normally permitted

查看:664
本文介绍了WCF:System.Net.SocketException - 每个套接字地址(协议/网络地址/端口)的一个用法通常被允许的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WCF服务和Web应用程序。 Web应用程序使得在一个连续的方式a.k.a轮询这个WCF服务电话。在我们的生产环境,我收到此错误很少。因为,这是一个内部活动的用户还没有意识到的时候被抛出此错误的。

I have a WCF service and a Web application. Web application makes calls to this WCF service in a continous manner a.k.a polling. In our production environment, I receive this error very rarely. Since, this is an internal activity users were not aware of when this error is thrown.

无法连接
   HTTP://localhost/QAService/Service.svc
  TCP错误code 10048:只有一个使用
  每个套接字地址
  (协议/网络地址/端口)是
  通常允许127.0.0.1:80。 --->
  System.Net.WebException:无法
  连接到远程服务器--->
  System.Net.Sockets.SocketException:
  只有每个套接字地址的一个用法
  (协议/网络地址/端口)是
  通常允许127.0.0.1:80

Could not connect to http://localhost/QAService/Service.svc. TCP error code 10048: Only one usage of each socket address (protocol/network address/port) is normally permitted 127.0.0.1:80. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted 127.0.0.1:80

我有再现于我们的开发/ QA环境这种行为的麻烦。我已经确定了客户端连接在try..catch..finally代码块封闭。还是不明白是什么原因造成这个问题..任何一个意识到这一点?

I am having trouble in reproducing this behaviour in our dev/qa environment. I have made sure that the client connection is closed in a try..catch..finally block. Still don't understand what is causing this issue .. any one aware of this?

注意:我看了这个<一个href=\"http://stackoverflow.com/questions/828864/continuous-rapid-calls-to-wcf-service-returns-a-only-one-usage-of-each-socket-a\">SO问题,但不能似乎回答我的问题,所以它不是重复的问题。

Note: I've looked at this SO question, but not seems to be answering my problem, so it is not repeated questions.

推荐答案

您是超载TCP / IP协议栈。视窗(我认为其实所有套接字协议栈)对可以快速连续打开插槽的数量的限制,由于插座获得如何在正常操作下关闭。每当关闭套接字,它进入一定时间(240秒IIRC)TIME_WAIT状态。每次查询的时候,一个插座被消耗了默认的动态范围(我认为它大约5000动态端口略高于1024),以及每个调查结束的时间,特定的插座进入TIME_WAIT。如果轮询频率足够高,你最终会消耗掉所有可用的端口,这将导致TCP错误的10048。

You are overloading the TCP/IP stack. Windows (and I think all socket stacks actually) have a limitation on the number of sockets that can be opened in rapid sequence due to how sockets get closed under normal operation. Whenever a socket is closed, it enters the TIME_WAIT state for a certain time (240 seconds IIRC). Each time you poll, a socket is consumed out of the default dynamic range (I think its about 5000 dynamic ports just above 1024), and each time that poll ends, that particular socket goes into TIME_WAIT. If you poll frequently enough, you will eventually consume all of the available ports, which will result in TCP error 10048.

一般情况下,WCF试图通过集中连接之类的东西,以避免这个问题。这通常是与不会通过互联网内部服务的情况。我不知道是否有任何wsHttp绑定的支持连接池,但netTcp结合应该。我会假设命名管道不会遇到这个问题。我不能说的MSMQ绑定。

Generally, WCF tries to avoid this problem by pooling connections and things like that. This is usually the case with internal services that are not going over the internet. I am not sure if any of the wsHttp bindings support connection pooling, but the netTcp binding should. I would assume named pipes does not run into this problem. I couldn't say for the MSMQ binding.

有两种解决方案,您可以使用来解决这个问题。您可以增加动态端口范围,或减少TIME_WAIT的时期。前者可能是更安全的路线,但是如果你是消费插座极高的容量(这听起来并不像您的方案的情况下),减少TIME_WAIT是一个更好的选择(或者两者一起)。

There are two solutions you can use to get around this problem. You can either increase the dynamic port range, or reduce the period of TIME_WAIT. The former is probably the safer route, but if you are consuming an extremely high volume of sockets (which doesn't sound like the case for your scenario), reducing TIME_WAIT is a better option (or both together.)

更改动态端口范围


  1. 开启注册表编辑器。

  2. 开启键HKLM \\系统\\ CurrentControlSet \\服务\\ TCPIP \\参数

  3. 编辑(或创建为DWORD)的MaxUserPort值。

  4. 将其设置为一个较大的数字。 (即65534)

更改TIME_WAIT延迟


  1. 开启注册表编辑器。

  2. 开启键HKLM \\系统\\ CurrentControlSet \\服务\\ TCPIP \\参数

  3. 编辑(或创建为DWORD)的TCPTimeWaitDelay。

  4. 将其设置为一个较低的数字。值以秒为单位。 (即60℃1分钟的延迟)

一个以上的解决方案应该可以解决你的问题。如果更改端口范围后仍然存在,我会看到试着提高轮询的时间,因此发生较少...这会给你更多的余地来解决时间等待时延。我会改变时间等待时延作为最后的手段。

One of the above solutions should fix your problem. If it persists after changing the port range, I would see try increasing the period of your polling so it happens less frequently...that will give you more leeway to work around the time wait delay. I would change the time wait delay as a last resort.

这篇关于WCF:System.Net.SocketException - 每个套接字地址(协议/网络地址/端口)的一个用法通常被允许的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆