在Web服务的错误处理 [英] Error handling in web service

查看:120
本文介绍了在Web服务的错误处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何传达一个错误的Web服务的消费者?

How do you communicate an error to the web service consumer ?

例如,我的web服务具有以下功能:插入到员工,而db.Suppose插入数据,数据库给了一个错误,我应该是通知用户有关错误的最好方式。

For example, my web service has a function to insert employee into db.Suppose while inserting the data , the database gave an error,what should be the best way to inform the user about the error.

一种方法是描绘它通过Web服务方法的返回值,但什么时候该函数应该返回像员工一个复杂的对象时没有错误做的,当有一个将发送一个错误字符串错误?

One way is to depict it through the return value of the web service method but what to do when the function is supposed to return a complex object like employee when there is no error ,and will send an error string when there is an error ?

推荐答案

对于SOAP:这就是故障用于

For SOAP: That is what faults are used for

SOAP错误被用来携带在SOAP消息中的错误信息。该故障是SOAP什么异常是一种编程语言。

SOAP faults are used to carry error information within a SOAP message. The fault is for SOAP what an exception is for a programming language.

当您的客户端的请求成功,您发回的员工结构,当它失败了,你发回一个挑剔的的什么地方出了错细节。

When your client's request succeeds, you send back a valid response with the Employee structure, when it fails, you send back a fault with details of what went wrong.

休息:使用 HTTP错误codeS

For REST: Use HTTP Error Codes

与SOAP,REST Web服务没有一个约定返回错误,但最简单的就是使用的这个大家都明白。

Unlike SOAP, REST web services do not have a convention for returning errors but the simplest is to use the ones everybody understands.

例如,当一些数据库等上happend你可能会发送一个HTTP 404的记录丢失时没有找到,一个HTTP 500服务器错误,并返回HTTP 200 OK与你的结果时,一切都很好,很正常。

For example you might send a HTTP 404 Not Found when a record is missing, a HTTP 500 Server Error when something happend on the database etc, and return HTTP 200 OK with your result when everything is fine and dandy.

这篇关于在Web服务的错误处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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