[英]WCF & keepAliveEnabled - More than two sockets at the same time?
I try to make a multiple-thread requester in order to test answer time of my server. 我尝试制作一个多线程请求程序以测试服务器的应答时间。
My server is a WCF webservice, and my client has a service reference to this webservice. 我的服务器是WCF Web服务,我的客户端对此Web服务有服务引用。
WCF respect HTTP specifications, and I see on many websites WCF is Keep-Alive enabled by default. WCF遵守HTTP规范,而且我在许多网站上都看到WCF默认情况下启用了Keep-Alive。 By only two connections from the same client are authorized at same time.
同一客户端只有两个连接被同时授权。
So, when I try to create 100 threads, only two of them are processing at the same time. 因此,当我尝试创建100个线程时,它们中只有两个正在同时处理。 So, after few loops, a lot of threads are in timeout.
因此,经过几次循环后,许多线程处于超时状态。
I try to follow this article : WCF wsHttpBinding with http keepalive but it didn't work. 我尝试按照这篇文章进行操作: WCF wsHttpBinding与http keepalive,但是没有用。
Here is my app config (modified by the Service Reference) : 这是我的应用程序配置(由服务参考修改):
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ISabIn" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://xxx.xxx.xxx.xxx:xxx/SabIn.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ISabIn" contract="TestWs.ISabIn"
name="BasicHttpBinding_ISabIn" />
</client>
</system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
I try to use customBinding in the appCode, like this article : HTTP Keep-alive and ServiceHost / C#? 我尝试在appCode中使用customBinding,例如本文: HTTP Keep-alive和ServiceHost / C#? but, when I execute my software, an erreor appears about "application/xml".
但是,当我执行软件时,出现关于“ application / xml”的错误。 If I try to translate in english, it would be somehting like "your client don't manage the application/xml message".
如果我尝试用英语翻译,那会有点像“您的客户端不管理应用程序/ xml消息”。
I need to do real-time transactions, and I can't if WCF only manage two sockets at same time... 我需要进行实时交易,如果WCF仅同时管理两个套接字,我将无法执行...
Can you help me ? 你能帮助我吗 ?
PS : I can post the code of my client, but I'm not sure is useful since I know the problem is a sockets limitation. PS:我可以发布客户端的代码,但是由于我知道问题是套接字限制,所以我不确定是否有用。
SOLUTION (thnaks to Spender) : at the beginning of your code, change the default value (it is 2) in System.Net.ServicePointManager.DefaultConnectionLimit 解决方案(对Spender表示感谢):在代码开头,更改System.Net.ServicePointManager.DefaultConnectionLimit中的默认值(它是2)。
Isn't this caused by default .net limits on HTTP request to a single host? 这不是默认情况下对单个主机的HTTP请求的.net限制引起的吗? This is because
ServicePointManager.DefaultConnectionLimit
defaults to 2. 这是因为
ServicePointManager.DefaultConnectionLimit
默认为2。
When you issue an HTTP request, internally, a ServicePoint
instance is created to manage the connections to a specific host. 当您发出HTTP请求时,在内部会创建一个
ServicePoint
实例来管理到特定主机的连接。 Make a new request to the same host, and it will use the same ServicePoint instance for connection management. 向同一主机发出新请求,它将使用相同的ServicePoint实例进行连接管理。
You can manipulate the limit for a single host with the following code: 您可以使用以下代码来控制单个主机的限制:
var serviceUri = new Uri("http://xxx.xxx.xxx.xxx:xxx/SabIn.svc");
var servicePoint = System.Net.ServicePointManager.FindServicePoint(serviceUri);
servicePoint.ConnectionLimit = int.MaxValue;
I believe you can also handle this in web.config
/ app.config
but I'm not sure if you can tweak limits associated with a single ServicePoint. 我相信您也可以在
web.config
/ app.config
处理此问题,但是我不确定是否可以调整与单个ServicePoint相关的限制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.