private static Message ConfigureResponseMessage(Message message) { if (message == null) { return(null); } HttpResponseMessageProperty responseProperty = new HttpResponseMessageProperty(); HttpResponseMessage httpResponseMessage = message.ToHttpResponseMessage(); if (httpResponseMessage == null) { responseProperty.StatusCode = HttpStatusCode.InternalServerError; responseProperty.SuppressEntityBody = true; } else { responseProperty.StatusCode = httpResponseMessage.StatusCode; if (httpResponseMessage.ReasonPhrase != null && httpResponseMessage.ReasonPhrase != DefaultReasonPhrase) { responseProperty.StatusDescription = httpResponseMessage.ReasonPhrase; } CopyHeadersToNameValueCollection(httpResponseMessage.Headers, responseProperty.Headers); HttpContent content = httpResponseMessage.Content; if (content != null) { ObjectContent objectContent = content as ObjectContent; if (objectContent != null) { objectContent.DetermineWriteSerializerAndContentType(); } CopyHeadersToNameValueCollection(httpResponseMessage.Content.Headers, responseProperty.Headers); } else { responseProperty.SuppressEntityBody = true; } } message.Properties.Clear(); message.Headers.Clear(); message.Properties.Add(HttpResponseMessageProperty.Name, responseProperty); return(message); }