为什么 ProvideFault 会捕获我的 TimeoutException?

发布于 2025-01-01 09:29:12 字数 479 浏览 4 评论 0原文

我有一个通过 wcf 进行通信的 ProvideFault() 服务。对于大多数异常,我们希望捕获它们,将它们转换为 FaultException,并让调用者处理它,因此我们实现了 ProvideFault()

到目前为止,一切都很好,而且大部分都有效。但是这个服务正在调用另一个服务,有时会抛出TimeoutException;我们不想捕获该异常,而是让它冒泡给调用者(或者甚至在必要时抛出一个新的 TimeoutException )。问题是,当该方法抛出 TimeoutException 时,ProvideFault() 会尝试处理它并将其转换为FaultException。

如何强制 wcf 让它以 TimeoutException 的形式冒泡?

I've got a ProvideFault() service that communicates through wcf. For most exceptions, we want to catch them, convert them into a FaultException<CustomException>, and let the caller handler it, so we've implemented ProvideFault().

So far, so good, and it mostly works. But this service is calling another service, which sometimes throws a TimeoutExeption; we don't want to catch that exception, but instead let it bubble up to the caller (or even throw a new TimeoutException, if necessary). The problem is that when the method throws a TimeoutException, ProvideFault() tries to deal with it and turn it into a FaultException.

How do I force wcf to let it bubble up as a TimeoutException?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风吹过旳痕迹 2025-01-08 09:29:12

WCF 将异常作为FaultException 发送,因此您无法冒泡超时异常。

然而,您可以做的是发送:

FaultException<TimeoutException>

WCF sends exceptions as FaultExceptions, so you cannot bubble up a Timeout Exception.

What you can do however is to send up a:

FaultException<TimeoutException>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文