Exemplo n.º 1
0
        public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
        {
            Log.Error("Unhandled exception in service (JSON interface)", error);
            JsonError errorObject = new JsonError {
                ExceptionType = error.GetType().ToString(), Message = error.Message, StackTrace = error.StackTrace
            };

            // format the exception/message with JSON
            fault = Message.CreateMessage(version, "", errorObject, new DataContractJsonSerializer(typeof(JsonError)));

            // set http status code to 500 and content type to JSON
            HttpResponseMessageProperty httpResponse = new HttpResponseMessageProperty();

            httpResponse.Headers[HttpResponseHeader.ContentType] = "application/json";
            httpResponse.StatusCode = HttpStatusCode.InternalServerError;

            fault.Properties.Add(WebBodyFormatMessageProperty.Name, new WebBodyFormatMessageProperty(WebContentFormat.Json));
            fault.Properties.Add(HttpResponseMessageProperty.Name, httpResponse);
        }
Exemplo n.º 2
0
        public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
        {
            Log.Error("Unhandled exception in service (JSON interface)", error);
            JsonError errorObject = new JsonError { ExceptionType = error.GetType().ToString(), Message = error.Message, StackTrace = error.StackTrace };

            // format the exception/message with JSON
            fault = Message.CreateMessage(version, "", errorObject, new DataContractJsonSerializer(typeof(JsonError)));

            // set http status code to 500 and content type to JSON
            HttpResponseMessageProperty httpResponse = new HttpResponseMessageProperty();
            httpResponse.Headers[HttpResponseHeader.ContentType] = "application/json";
            httpResponse.StatusCode = HttpStatusCode.InternalServerError;

            fault.Properties.Add(WebBodyFormatMessageProperty.Name, new WebBodyFormatMessageProperty(WebContentFormat.Json));
            fault.Properties.Add(HttpResponseMessageProperty.Name, httpResponse);
        }