예제 #1
0
        public void WriteOutputContent(MediaType mediaType, IFormat format)
        {
            if (mediaType == null)
            {
                throw new ArgumentNullException("mediaType", "mediaType cannot be null.");
            }

            if (format == null)
            {
                throw new ArgumentNullException("format", "format cannot be null.");
            }

            object resp = this.ResponseObject;
            this.Headers["Content-Type"] = format.ContentType(mediaType);

            if (resp != null)
            {
                format.Serialize(mediaType, resp, this.OutputStream);
            }
        }
예제 #2
0
        public void WriteOutputContent(MediaType mediaType, IFormat format)
        {
            if (mediaType == null)
            {
                throw new ArgumentNullException("mediaType", "mediaType cannot be null.");
            }

            if (format == null)
            {
                throw new ArgumentNullException("format", "format cannot be null.");
            }

            string contentType = format.ContentType(mediaType);

            if (contentType.Contains("*"))
            {
                throw new InvalidOperationException(
                    string.Format(
                        CultureInfo.InvariantCulture,
                        "Format {0} returned a Content-Type of {1} for the chosen media type of {2}. Writing a wildcard Content-Type to the response is not supported.",
                        format.GetType(),
                        contentType,
                        mediaType));
            }

            object resp = this.ResponseObject;
            this.httpResponse.ContentType = contentType;

            if (resp != null)
            {
                format.Serialize(mediaType, resp, this.httpResponse.OutputStream);
            }
        }