3

I would like to return a custom HTTP status code from a RESTful WCF web service when a certain condition is met.

I do not want to use the standard HTTP status codes; instead, I would like to return e.g., a 514 status code which means something to the calling user.

Is this possible with WebOperationContext.Current.OutgoingResponse?

1 Answer 1

3

OutgoingResponse.StatusCode is where you'd set the status code, but it's an HttpStatusCode enum, not an integer value.

You could cast a custom value int to HttpStatusCode, but I'm not sure what the framework would do with it; most likely it would throw, but it can't hurt to try.

Although the HTTP spec doesn't disallow custom response codes, it's probably not a good idea to go that route unless you must. Perhaps a custom response header would be better?

If you must go the custom status code route, another option might be to use ASP.NET compatibility mode. That would allow you to use HttpContext.Current.Response.StatusCode, which is an int. You'd have to be hosted in IIS for this to work, however, and I don't know your architecture.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.