I have a WCF REST service whose interface methods are annotated with [WebGet(..., ResponseFormat = WebMessageFormat.Json)]
and normally provide JSON-formatted responses. Right now the code indicates errors with:
throw new WebFaultException<string>("helpful message",HttpStatusCode.BadRequest);
The problem is that the Content-Type on the response is still application/json
even though the body is just plain text, not JSON encoded. I can make a helper to generate my fault exceptions that will set WebOperationContext.Current.OutgoingResponse.ContentType = "text/plain";
, but if there's a quick fix in the WCF layer that would just set the content type for these types of exceptions that would be preferable. What's the cleanest way to do this?