Web服务会抛出异常或结果对象 [英] Should web services throw exceptions OR result objects

查看:208
本文介绍了Web服务会抛出异常或结果对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道我完全乐意在Web服务中抛出异常是一个好主意。如果不是堆栈跟踪,我不会介意。这不是我不喜欢的东西。



我已经对几个实现进行了研究,并没有对此达成共识。例如,CampaignMonitor会返回一个Result对象,而另外一些则不会。



从结构上讲,我不确定返回一个返回对象是否有意义,但是我对Return对象的看法是对最终用户来说是一个更优雅的解决方案。



有没有人有任何更好的解决方案?



编辑



BTW我正在使用ASMX网络服务,而不是一个选项来打开CustomErrors。

$ b $你在说什么堆栈跟踪?你试过了吗?



在ASMX和WCF服务中,未捕获的异常将被转换为SOAP Fault。在这两种情况下,可以将其配置为不包括任何堆栈跟踪。实际上,这是WCF中的默认值。



所以,返回错误的正确方法是出现故障。产生故障的一种方式是抛出并且不处理异常。


I'm not sure I'm completely happy that throwing exceptions in web services is a good idea. I wouldnt mind as much if it wasn't for the stack trace. This is not something I wan't.

I have researched around several implementations and there really doesn't seem to be a consensus on this. CampaignMonitor for example does return a Result object, yet others don't.

Architecturally, I'm not sure returning a return object makes sense, surely an exception is an exception, but what I do like about a Return object is that it is a more graceful solution for the end user.

Does anyone have any better solutions?

EDIT

BTW I am using ASMX web services, where turning CustomErrors on is not an option.

解决方案

What stack trace are you talking about? Have you tried this?

In both ASMX and WCF services, an uncaught exception will be translated into a SOAP Fault. In both cases, they can be configured to not include any stack trace. In fact, that's the default in WCF.

So, the proper way to return an error like this is through a fault. One way to generate faults is to throw and not handle an exception.

这篇关于Web服务会抛出异常或结果对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆