寻求有关 WCF 故障合同的建议
我遇到的情况是,我希望能够区分 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我同意达林。
看一下:
WCF 错误处理无故障合同
它与您的非常相似问题。
欲了解更多信息:
http://www.c-sharpcorner.com/ UploadFile/ankithakur/ExceptionHandlingWCF12282007072617AM/ExceptionHandlingWCF.aspx
I agree Darin.
Have a look at:
WCF Error Handling without fault contract
It's very similar to your problem.
for more information:
http://www.c-sharpcorner.com/UploadFile/ankithakur/ExceptionHandlingWCF12282007072617AM/ExceptionHandlingWCF.aspx
使用不同的故障契约是 WCF 中的解决方法。还将异常处理代码集中在自定义错误处理程序 是个好主意。这样,您不再需要编写所有这些 try/catch 并在 catch 子句中将异常转换为所有服务操作中的故障契约。
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.