Пример #1
0
        public HttpResponseMessageWrapper(HttpRequestMessage msg, T type, HttpStatusCode statusCode)
            : base(statusCode)
        {
            MessageWrapper <T> messageWrapper = new MessageWrapper <T>()
            {
                StatusCode = statusCode, Value = type
            };

            this.Content = new ObjectContent <MessageWrapper <T> >(messageWrapper);
            if (HttpHeaderHelper.IsPhoneDevice(msg))
            {
                this.StatusCode = HttpStatusCode.OK;
            }

            string messageText = this.Content != null?msg.Content.ReadAsStringAsync().Result : "(empty)";

            string tracemsg = String.Format(
                "\nWeb Response: Status: {0} {1}; Content-Type: {2}\n" +
                "Web Response Body: {3}",
                (int)statusCode,
                statusCode,
                msg.Content.Headers.ContentType,
                messageText);

            TraceLog.TraceLine(tracemsg, TraceLog.LogLevel.Detail);
        }
Пример #2
0
        public HttpResponseMessageWrapper(HttpRequestMessage msg, HttpStatusCode statusCode)
            : base(statusCode)
        {
            MessageWrapper <T> messageWrapper = new MessageWrapper <T>()
            {
                StatusCode = statusCode
            };

            this.Content = new ObjectContent <MessageWrapper <T> >(messageWrapper);

            if (HttpHeaderHelper.IsPhoneDevice(msg))
            {
                this.StatusCode = HttpStatusCode.OK;

                // this constructor means no body, which indicates a non-200 series status code
                // since we switched the real HTTP status code to 200, we need to turn off caching
                this.Headers.CacheControl = new CacheControlHeaderValue()
                {
                    NoCache = true
                };
            }
        }