WCF分布式开发常见错误(20):TimeoutException was unhandled
2009-07-22 22:50
525 查看
在进行WCF应用程序开发的时候,如果大量客户端发送请求到WCF服务,往往会出现这个异常,超时。WCF服务响应超时。没有在指定的时间00:01:00内打开操作,分配给这个操作的时间或许只是超时时间的一部分。
错误信息如下:
The open operation did not complete within the allotted timeout of 00:01:00. The time allotted to this operation may have been a portion of a longer timeout.
【1】错误截图:
【2】原因分析:
这个超时异常的产生,直接导致的原因是,大量的客户端请求发送给服务。我这里使用的100个客户端,实例化100个代理。然后请求。模拟客户端的大量并发请求。服务基本延时100MS。模拟处理。这里大概在10个请求的时候,服务处理出现阻塞。进而等待,最后出现超时异常。
【3】解决办法:
涉及到大量请求的时候,可以考虑使用WCF的 ServiceThrottlingBehavior ,包括三个重要的属性: MaxConcurrentCalls、MaxConcurrentSessions、MaxConcurrentInstances,它们分别的默认值为16,10和26。
这里我们设置一下服务的限流行为就可以了。具体如下:
serviceBehaviors>
<behavior name="WCFService.WCFServiceBehavior">
<serviceTimeouts transactionTimeout="00:01:00"/>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceThrottling maxConcurrentCalls="1000" maxConcurrentInstances="1000" maxConcurrentSessions="1000"/>-->
</behavior>
</serviceBehaviors>
这里1000可以修改,根据你的实际WCF服务需求量。服务激活类型和实例调用方式。然后进行调整。修改完毕以后,重新启动服务,基本就正常了。
最后是Demo程序下载:/Files/frank_xl/7.WCFServiceConcurrencyClientsFrankXuLei.rar。
参考文章:http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicethrottlingbehavior_properties.aspx
错误信息如下:
The open operation did not complete within the allotted timeout of 00:01:00. The time allotted to this operation may have been a portion of a longer timeout.
【1】错误截图:
【2】原因分析:
这个超时异常的产生,直接导致的原因是,大量的客户端请求发送给服务。我这里使用的100个客户端,实例化100个代理。然后请求。模拟客户端的大量并发请求。服务基本延时100MS。模拟处理。这里大概在10个请求的时候,服务处理出现阻塞。进而等待,最后出现超时异常。
【3】解决办法:
涉及到大量请求的时候,可以考虑使用WCF的 ServiceThrottlingBehavior ,包括三个重要的属性: MaxConcurrentCalls、MaxConcurrentSessions、MaxConcurrentInstances,它们分别的默认值为16,10和26。
名称 | 说明 | |
---|---|---|
MaxConcurrentCalls | 获取或设置一个值,该值指定整个 ServiceHost 中正在处理的最多消息数。 | |
MaxConcurrentInstances | 获取或设置一个值,该值指定服务中可以一次执行的最多 InstanceContext 对象数。 | |
MaxConcurrentSessions | 获取或设置一个指定 ServiceHost 对象可一次接受的最多会话数的值。 |
serviceBehaviors>
<behavior name="WCFService.WCFServiceBehavior">
<serviceTimeouts transactionTimeout="00:01:00"/>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceThrottling maxConcurrentCalls="1000" maxConcurrentInstances="1000" maxConcurrentSessions="1000"/>-->
</behavior>
</serviceBehaviors>
这里1000可以修改,根据你的实际WCF服务需求量。服务激活类型和实例调用方式。然后进行调整。修改完毕以后,重新启动服务,基本就正常了。
最后是Demo程序下载:/Files/frank_xl/7.WCFServiceConcurrencyClientsFrankXuLei.rar。
参考文章:http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicethrottlingbehavior_properties.aspx
相关文章推荐
- WCF分布式开发常见错误(20):TimeoutException was unhandled
- WCF分布式开发常见错误(20):TimeoutException was unhandled
- WCF分布式开发常见错误解决(12):The server was unable to process the request,服务无法处理请求
- WCF分布式开发常见错误(12):The server was unable to process the request,服务无法处理请求
- WCF分布式开发常见错误(22):The caller was not authenticated...如何在XP系统为WCF设置可信任的证书
- WCF分布式开发常见错误(12):The server was unable to process the request,服务无法处理请求
- WCF分布式开发常见错误(22):The caller was not authenticated...如何在XP系统为WCF设置可信任的证书
- WCF分布式开发常见错误解决(9):无终结点监听,There was no endpoint listening at
- WCF分布式开发常见错误(13):The transaction under which this method call was executing ,此方法调用的事务被异步中断
- WCF分布式开发常见错误解决(9):无终结点监听,There was no endpoint listening at
- WCF分布式开发常见错误(29):Unrecognized attribute 'targetFramework' (未识别的属性'targetFramework' )
- WCF分布式开发常见错误(18):Binding validation failed 绑定协议验证失败
- WCF分布式开发常见错误(11):There is already a listener on IP endpoint ,IP 终结点 已经存在侦听器
- WCF分布式开发常见错误(21):unable to open its IChannelListener.分发器未能打开侦听器
- WCF分布式开发常见错误解决(1):An error occurred while attempting to find services at...添加服务引用出错
- WCF分布式开发常见错误(27):Secure channel cannot be opened
- WCF分布式开发常见错误(18):Binding validation failed 绑定协议验证失败
- WCF分布式开发常见错误(13):此方法调用的事务被异步中断
- WCF分布式开发常见错误(21):unable to open its IChannelListener.分发器未能打开侦听器
- WCF分布式开发常见错误(2)无法从传输连接中读取数据: 远程主机强迫关闭了一个现有的连接