我的WCF服务关闭中有以下代码
private const double timeSpanInMS = 250;
尝试{
var serviceHostCloseTimeout = TimeSpan.FromMilliseconds(timeSpanInMS); serviceHost.Close(serviceHostCloseTimeout);
} catch(TimeoutException){}
但我可以看到,在某些情况下,Close正在接受1秒。根据API规范,它应该在250毫秒内超时,抛出TimeoutException。
我还尝试在打开serviceHost之前设置CloseTimeout属性,但没有效果。
在这种情况下,我们总是假设我们使用API的方式存在一些问题。
任何人都遇到了这个问题,或者我错误地使用了API?
解决方案
嗨Sudheesh,
在我的选项中,你的API使用没有问题。
我也无法抛出CloseTimeOut异常。
根据文档,当主机关闭时间到期时,它应该抛出异常。但是,我试过"host.Closing + = Host_Closing; host.Closed + = Host_Closed;" with thread.sleep,它也不会抛出异常。
您是否在生产或开发中获得任何超时异常?
根据我的经验,在传输大数据或文件时,SendTimeout for Binding最常发生超时。关闭时间没有必要错。
最好的问候,
Edward
Hi,
I have the following piece of code in my WCF service shutdown
private const double timeSpanInMS = 250;
try {
var serviceHostCloseTimeout = TimeSpan.FromMilliseconds(timeSpanInMS); serviceHost.Close(serviceHostCloseTimeout);
}catch(TimeoutException) {}
But I could see that in some cases the Close is taking up to 1 sec. As per the API specification it shall timeout always in 250 ms throwing TimeoutException.
I also tried setting the CloseTimeout property before opening the serviceHost, but no effect.
In this kind of scenarios we shall always assume there is some problem in the way we are using API.
Anybody faced this issue, or I am using the API wrongly?
解决方案
Hi Sudheesh,
In my option, there is no problem in your API using.
I could not throw the CloseTimeOut exception either.
Per the document, it should throw exception when the host close expires the time settings. But, I tried "host.Closing += Host_Closing; host.Closed += Host_Closed;" with a thread.sleep, it would not throw exception either.
Did you get any get any timeout exception in production or development?
As my experience, the timeout most happen with SendTimeout for Binding while transfer large data or file. There is no need to wrong about close time out.
Best Regards,
Edward
更多推荐
ServiceHost.Close(Timespan)未按预期超时
发布评论