ServiceHost.Close(Timespan)未按预期超时 [英] The ServiceHost.Close(Timespan) is not timing out as expected

查看:64
本文介绍了ServiceHost.Close(Timespan)未按预期超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我的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)未按预期超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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