【发布时间】:2012-04-04 17:45:24
【问题描述】:
我从代码调用服务,如果服务因任何原因停止,它会给我 EndPointNotFound 异常。
<binding name="NormalMode" transferMode="Buffered" receiveTimeout="24.20:31:23.6470000">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="None" />
</binding>
我没有设置 openTimeOut,所以它会考虑默认的 1 分钟超时。
我是这样调用服务的,
private void MyServiceCall(Action serviceCall)
{
try
{
if (serviceCall != null)
{
serviceCall();
}
}
catch (EndpointNotFoundException endpointNotFoundException)
{
throw new EndpointNotFoundException(endpointNotFoundException.Message, endpointNotFoundException);
}
我的问题是,如果服务停止,那么抛出 EndPointNotFoundException 需要 1 分钟吗??
编辑::
在这种情况下,我知道服务已停止。我通过停止服务来测试它。问题是我们已经开发了断开连接的 senario,如果服务停止,它将返回默认数据,但这需要时间,所以我正在调查是否是 openTimeOut 负责它。
【问题讨论】:
-
请问你为什么在一个捕获
EndpointNotFoundException的catch块中抛出一个EndpointNotFoundException? -
@Thorsten Dittmar:非常好的问题。我希望有人至少在重新抛出异常之前记录它。
-
如果需要重新抛出异常,
throw就足够了。 -
我在抛出异常之前记录了它,我已经删除了那些行。如果我只写 throw 会有什么不同吗?我的意思是客户端的任何堆栈差异
-
Throw 将抛出确切的异常,确切的堆栈跟踪,就像它在原始抛出时一样。如果你不想这样,抛出你在 catch 中遇到的异常:
catch(Exception ex) { throw ex; }