【问题标题】:What are the Implications of WCF TimeoutException vs CommunicationException on method execution?WCF TimeoutException 与 CommunicationException 对方法执行有何影响?
【发布时间】:2019-10-11 23:08:15
【问题描述】:

我正在调用 WCF 服务,该服务将启动一批信用卡费用。如果发生异常,我想知道它是否在方法执行和实际收费之前发生。例如,对于 TimeoutException,无法知道 WCF 方法是否已执行,因此我需要确保在调查情况之前不会重试这些费用。但是如果网络刚刚关闭,或者服务器证书过期,或者在方法实际执行之前发生了其他任何事情,我可以解锁我的记录以便稍后重试,而无需人工干预。

try
{
    var response = wcfClient.ProcessBatch(paymentBatch);
    wcfClient.Close();

    //...
}
catch(CommunicationException)
{
    //Safe to assume ProcessBatch did not execute?

    wcfClient.Abort();
}
catch(TimeoutException)
{
    //Indeterminate state. Have to assume operation may have succeeded server-side

    wcfClient.Abort();
}
catch(Exception)
{
    //Assuming operation may have succeeded server-side
}

这是使用wsHttpBindingCommunicationException 是否保证该方法没有执行,或者它也可以在响应期间被抛出?

【问题讨论】:

    标签: wcf exception


    【解决方案1】:

    根据the CommunicationException documentation on MSDN,CommunicationException Exceptionon 是错误的超类,分为两个子类别,都与 SOAP 数据报中的错误有关。

    相反,TimeoutException 非常简单:“分配给进程或操作的时间到期时引发的异常。”分配的时间可能是由服务的所有者设置的,您可能有也可能没有覆盖它的机制。

    为了将来参考,两次快速 Bing 搜索返回了本文引用的两篇文章。

    【讨论】:

    • “两个子类别” - 你的意思是 FaultExceptionFaultException<TDetail>?这些是许多派生类型中的两种;我不知道类别。这些与这个问题有什么关系?我在这里找不到问题的答案。为了公平比较,我发现这些文档也出现在简单的 google 和 dadduckgo 搜索中......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-29
    • 2021-09-05
    • 2014-05-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多