JamesB
JamesB

Reputation: 325

What is the correct HTTP Status Code for a WCF Web service to return when the request data content is well formed, but fails data validation?

I am consuming a WCF web service. I am providing syntactically correct xml data, but one of the application specific codes provided is sometimes incorrect (correct datatype but not a valid value - passes the xsd though). The web service returns a detailed response message in the response body and an HTML Status Code of Bad Request 400. Due to the Bad Request 400 status code, the WCF web service proxy immediately raises an exception and the ResponseBody is never available to interrogate for the detailed message. The only way I can ever see the detailed validation message is to turn on web service tracing and look at the trace file (obviously that means rerunning the request and is very time consuming).

I think the Bad Request 400 status code is incorrect for this situation. What I am not clear on is what the correct status should be. Note: this is not WebAPI REST, this is WCF web service.

I think 200 OK would be fine as the actual request was well formed, but the content was invalid. Then look at the response body for the real status.

Best practice answers please.

Many thanks,

James

Upvotes: 0

Views: 476

Answers (1)

Benjamin Drolet
Benjamin Drolet

Reputation: 189

That would still be a 400 Status Code. The data was bad for some reason or another.

I could also see a 500 type response used as well, but it isn't necessarily unexpected data.

https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

Upvotes: 2

Related Questions