views:

126

answers:

2

I'm developing a web service (in asp.net) and I would like to have each web method report to whoever called it when an internal error occurs - for example when input validation has failed.

When I expose my web service with SOAP such errors can be reported by raising a SoapException. But what if I expose my web service with plain POST (aka Http-Post)? Other than returning a 500 Error HTTP status code, is there a standard for reporting errors or raising exceptions in this case?

+1  A: 

I've always just returned the 500 status code, along with a textual description of the error. Just make sure it's documented so the client can handle it correctly.

Marc Charbonneau
+2  A: 

Change the response object to contain a status filed, and error message (or only error message, and check at the receiver if empty), and set it properly instead of throwing an exception.

Sunny
Thanks for the answer - I was actually trying to avoid return a response object because that's not standard. I'd have to "invent" my own response object and a set of error codes for it to contain. I'm looking for an existing standard or protocol to do this. Might you know of such a thing?
urig
SOAP is the existing standard, and it has the mechanism to pass exceptions. If you wan to use "non-standard" invoking like POST, you need non-standard solution. When you use POST, for the outside world this is a "normal" page request, with XML response. So you need to put the status there ...
Sunny
... or return an error code (500), and in the body of the response put the error message.
Sunny