寻求有关 WCF 故障合同的建议

发布于 2024-10-02 04:47:52 字数 226 浏览 3 评论 0原文

我遇到的情况是,我希望能够区分 Web 服务中不同类型的错误。在 API 中,这通常是每个异常的单独异常,这是否意味着我应该在 WCF 中拥有多个故障契约?

这是首选方法吗?这似乎是 OO 的方法。我工作中的某人建议了错误代码,但我开始认为如果您发回异常,这似乎是违反直觉的。

有没有人遇到过类似的情况,如果有,您做出了哪些设计决策以及做出这些决策的原因?

谢谢,任何帮助将不胜感激。 杰米

I have a situation where I want to be able to distinguish between different types of errors within a web service. In an API this would usaully be a separate exception for each, does this mean I should have multiple fault contracts in WCF?

Is this the preferred approach, it seems the OO way to do it. Someone at my work suggested error codes but I'm starting to think it seems counter-intuative if you are sending an exception back.

Has anyone ever been in a similar situation, if so, what design decisions did you undertake and reasons for them?

Thanks, any help would be greatly appreciated.
Jamie

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

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

发布评论

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

评论(2

山色无中 2024-10-09 04:47:52

Having different fault contracts is the way to go in WCF. Also centralizing the exception handling code in a custom error handler is a good idea. This way you no longer need to write all those try/catch and in the catch clause transform the exception into a fault contract in all service operations.

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