Esempio n. 1
0
        /// <inheritdoc/>
        public override void SetDefaultContentHeaders(Type type, HttpContentHeaders headers, MediaTypeHeaderValue mediaType)
        {
            // Determine the content type or let base class handle it.
            MediaTypeHeaderValue newMediaType = null;

            if (ODataOutputFormatterHelper.TryGetContentHeader(type, mediaType, out newMediaType))
            {
                headers.ContentType = newMediaType;
            }
            else
            {
                // This is the case when a user creates a new ObjectContent<T> passing in a null mediaType
                base.SetDefaultContentHeaders(type, headers, mediaType);
            }

            // Set the character set.
            IEnumerable <string> acceptCharsetValues = Request.Headers.AcceptCharset.Select(cs => cs.Value);

            string newCharSet = String.Empty;

            if (ODataOutputFormatterHelper.TryGetCharSet(headers.ContentType, acceptCharsetValues, out newCharSet))
            {
                headers.ContentType.CharSet = newCharSet;
            }

            // Add version header.
            headers.TryAddWithoutValidation(
                ODataVersionConstraint.ODataServiceVersionHeader,
                ODataUtils.ODataVersionToString(ResultHelpers.GetODataResponseVersion(Request)));
        }
Esempio n. 2
0
        public IHttpActionResult GetMetadata()
        {
            DataTable Source = TestData.GetData();

            Tuple <IEdmModel, IEdmType> InferredEntityModel = Source.BuildEdmModel("Test", "Test");

            StringWriter Writer  = new StringWriter();
            XmlWriter    XWriter = XmlWriter.Create(Writer);

            XWriter.WriteProcessingInstruction("xml", "version='1.0'");

            if (CsdlWriter.TryWriteCsdl(InferredEntityModel.Item1, XWriter, CsdlTarget.OData, out IEnumerable <EdmError> errors))
            {
                XWriter.Flush();
                String XmlOutput = Writer.ToString();

                if (!String.IsNullOrWhiteSpace(XmlOutput))
                {
                    HttpResponseMessage Output = new HttpResponseMessage();

                    Output.StatusCode = HttpStatusCode.OK;
                    Output.Content    = new StringContent(XmlOutput);
                    Output.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/xml");
                    Output.Content.Headers.TryAddWithoutValidation(
                        ODataReturnNegotiatedContentResult.ODataServiceVersionHeader,
                        ODataUtils.ODataVersionToString(ODataVersion.V4));

                    return(ResponseMessage(Output));
                }
            }

            return(InternalServerError());
        }
        /// <inheritdoc/>
        public override void SetDefaultContentHeaders(Type type, HttpContentHeaders headers, MediaTypeHeaderValue mediaType)
        {
            // call base to validate parameters and set Content-Type header based on mediaType parameter.
            base.SetDefaultContentHeaders(type, headers, mediaType);

            headers.TryAddWithoutValidation(ODataServiceVersion, ODataUtils.ODataVersionToString(_version));
        }
Esempio n. 4
0
        public void GetVersionUtilTest()
        {
            //positive tests
            this.Assert.AreEqual(ODataUtils.StringToODataVersion(DataServiceVersion4), ODataVersion.V4,
                                 "Failed to parse Data Service Version string");

            this.Assert.AreEqual(ODataUtils.StringToODataVersion(DataServiceVersion4 + ";"), ODataVersion.V4,
                                 "Failed to parse Data Service Version string");

            this.Assert.AreEqual(ODataUtils.StringToODataVersion(DataServiceVersion4 + ";anything"), ODataVersion.V4,
                                 "Failed to parse Data Service Version string");

            this.Assert.AreEqual(ODataUtils.ODataVersionToString(ODataVersion.V4), DataServiceVersion4,
                                 "Failed to parse Data Service Version enum");

            //negative tests
            string[] invalidVersionStrings = { "randomstring", "V1.0", "1.5", "randomstring;1.0", "5.0", "1" };
            foreach (string s in invalidVersionStrings)
            {
                TestExceptionUtils.ExpectedException(
                    this.Assert,
                    () =>
                {
                    ODataUtils.StringToODataVersion(s);
                },
                    ODataExpectedExceptions.ODataException("ODataUtils_UnsupportedVersionHeader", s),
                    this.ExceptionVerifier
                    );
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ODataBatchContent"/> class.
        /// </summary>
        /// <param name="responses">The batch responses.</param>
        /// <param name="requestContainer">The dependency injection container for the request.</param>
        /// <remarks>This signature uses types that are AspNetCore-specific.</remarks>
        public ODataBatchContent(IEnumerable <ODataBatchResponseItem> responses, IServiceProvider requestContainer)
        {
            Initialize(responses, requestContainer);
            Headers[HeaderNames.ContentType] = String.Format(CultureInfo.InvariantCulture, "multipart/mixed;boundary=batchresponse_{0}", Guid.NewGuid());
            ODataVersion version = _writerSettings.Version ?? ODataVersionConstraint.DefaultODataVersion;

            Headers.Add(ODataVersionConstraint.ODataServiceVersionHeader, ODataUtils.ODataVersionToString(version));
        }
Esempio n. 6
0
        /// <inheritdoc/>
        public virtual async Task <HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken)
        {
            IHttpActionResult result = GetInnerActionResult();
            var response             = await result.ExecuteAsync(cancellationToken);

            ResultHelpers.AddServiceVersion(response, () => ODataUtils.ODataVersionToString(ResultHelpers.GetODataResponseVersion(Request)));
            return(response);
        }
Esempio n. 7
0
        /// <inheritdoc/>
        public async virtual Task ExecuteResultAsync(ActionContext context)
        {
            HttpResponse  response = context.HttpContext.Response;
            HttpRequest   request  = context.HttpContext.Request;
            IActionResult result   = GetInnerActionResult(request);
            await result.ExecuteResultAsync(context);

            ResultHelpers.AddServiceVersion(response, () => ODataUtils.ODataVersionToString(ResultHelpers.GetODataResponseVersion(request)));
        }
Esempio n. 8
0
        /// <inheritdoc/>
        public virtual async Task <HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken)
        {
            IHttpActionResult   result   = GetInnerActionResult(Request);
            HttpResponseMessage response = await result.ExecuteAsync(cancellationToken);

            response.Headers.Location = LocationHeader;
            ResultHelpers.AddEntityId(response, () => GenerateEntityId(Request));
            ResultHelpers.AddServiceVersion(response, () => ODataUtils.ODataVersionToString(ResultHelpers.GetODataResponseVersion(Request)));
            return(response);
        }
Esempio n. 9
0
        /// <inheritdoc/>
        public override void WriteResponseHeaders(OutputFormatterWriteContext context)
        {
            if (context == null)
            {
                throw Error.ArgumentNull("context");
            }

            Type type = context.ObjectType;

            if (type == null)
            {
                throw Error.ArgumentNull("type");
            }
            type = TypeHelper.GetTaskInnerTypeOrSelf(type);

            HttpRequest request = context.HttpContext.Request;

            if (request == null)
            {
                throw Error.InvalidOperation(SRResources.WriteToStreamAsyncMustHaveRequest);
            }

            HttpResponse response = context.HttpContext.Response;

            response.ContentType = context.ContentType.Value;

            MediaTypeHeaderValue contentType = GetContentType(response.Headers[HeaderNames.ContentType].FirstOrDefault());

            // Determine the content type.
            MediaTypeHeaderValue newMediaType = null;

            if (ODataOutputFormatterHelper.TryGetContentHeader(type, contentType, out newMediaType))
            {
                response.Headers[HeaderNames.ContentType] = new StringValues(newMediaType.ToString());
            }

            // Set the character set.
            MediaTypeHeaderValue currentContentType = GetContentType(response.Headers[HeaderNames.ContentType].FirstOrDefault());
            RequestHeaders       requestHeader      = request.GetTypedHeaders();

            if (requestHeader != null && requestHeader.AcceptCharset != null)
            {
                IEnumerable <string> acceptCharsetValues = requestHeader.AcceptCharset.Select(cs => cs.Value.Value);

                string newCharSet = string.Empty;
                if (ODataOutputFormatterHelper.TryGetCharSet(currentContentType, acceptCharsetValues, out newCharSet))
                {
                    currentContentType.CharSet = newCharSet;
                    response.Headers[HeaderNames.ContentType] = new StringValues(currentContentType.ToString());
                }
            }

            // Add version header.
            response.Headers[ODataVersionConstraint.ODataServiceVersionHeader] = ODataUtils.ODataVersionToString(ResultHelpers.GetODataResponseVersion(request));
        }
        public override async Task <HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken)
        {
            base.Request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            HttpResponseMessage response = await base.ExecuteAsync(cancellationToken);

            response.Headers.TryAddWithoutValidation(
                ODataServiceVersionHeader,
                ODataUtils.ODataVersionToString(ODataVersion.V4));

            return(response);
        }
Esempio n. 11
0
        /// <inheritdoc/>
        public override void SetDefaultContentHeaders(Type type, HttpContentHeaders headers, MediaTypeHeaderValue mediaType)
        {
            if (type == null)
            {
                throw Error.ArgumentNull("type");
            }
            if (headers == null)
            {
                throw Error.ArgumentNull("headers");
            }

            // When the user asks for application/json we really need to set the content type to
            // application/json; odata.metadata=minimal. If the user provides the media type and is
            // application/json we are going to add automatically odata.metadata=minimal. Otherwise we are
            // going to fallback to the default implementation.

            // When calling this formatter as part of content negotiation the content negotiator will always
            // pick a non null media type. In case the user creates a new ObjectContent<T> and doesn't pass in a
            // media type, we delegate to the base class to rely on the default behavior. It's the user's
            // responsibility to pass in the right media type.

            if (mediaType != null)
            {
                if (mediaType.MediaType.Equals("application/json", StringComparison.OrdinalIgnoreCase) &&
                    !mediaType.Parameters.Any(p => p.Name.Equals("odata.metadata", StringComparison.OrdinalIgnoreCase)))
                {
                    mediaType.Parameters.Add(new NameValueHeaderValue("odata.metadata", "minimal"));
                }

                headers.ContentType = (MediaTypeHeaderValue)((ICloneable)mediaType).Clone();
            }
            else
            {
                // This is the case when a user creates a new ObjectContent<T> passing in a null mediaType
                base.SetDefaultContentHeaders(type, headers, mediaType);
            }

            // In general, in Web API we pick a default charset based on the supported character sets
            // of the formatter. However, according to the OData spec, the service shouldn't be sending
            // a character set unless explicitly specified, so if the client didn't send the charset we chose
            // we just clean it.
            if (headers.ContentType != null &&
                !Request.Headers.AcceptCharset
                .Any(cs => cs.Value.Equals(headers.ContentType.CharSet, StringComparison.OrdinalIgnoreCase)))
            {
                headers.ContentType.CharSet = String.Empty;
            }

            headers.TryAddWithoutValidation(
                HttpRequestMessageProperties.ODataServiceVersionHeader,
                ODataUtils.ODataVersionToString(_version));
        }
Esempio n. 12
0
        /// <inheritdoc/>
        public async override Task ExecuteResultAsync(ActionContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            HttpResponse  response = context.HttpContext.Response;
            HttpRequest   request  = context.HttpContext.Request;
            IActionResult result   = GetInnerActionResult(request);
            await result.ExecuteResultAsync(context).ConfigureAwait(false);

            ResultHelpers.AddServiceVersion(response, () => ODataUtils.ODataVersionToString(request.GetODataVersion()));
        }
Esempio n. 13
0
        /// <inheritdoc/>
        public async virtual Task ExecuteResultAsync(ActionContext context)
        {
            HttpRequest   request  = context.HttpContext.Request;
            HttpResponse  response = context.HttpContext.Response;
            IActionResult result   = GetInnerActionResult(request);
            Uri           location = GenerateLocationHeader(request);

            response.Headers["Location"] = location.AbsoluteUri;
            // Since AddEntityId relies on the response, make sure to execute the result
            // before calling AddEntityId() to ensure the response code is set correctly.
            await result.ExecuteResultAsync(context);

            ResultHelpers.AddEntityId(response, () => GenerateEntityId(request));
            ResultHelpers.AddServiceVersion(response, () => ODataUtils.ODataVersionToString(ResultHelpers.GetODataResponseVersion(request)));
        }
Esempio n. 14
0
        public override void WriteResponseHeaders(OutputFormatterWriteContext context)
        {
            HttpRequest  request  = context.HttpContext.Request;
            HttpResponse response = context.HttpContext.Response;

            //// When the user asks for application/json we really need to set the content type to
            //// application/json; odata.metadata=minimal. If the user provides the media type and is
            //// application/json we are going to add automatically odata.metadata=minimal. Otherwise we are
            //// going to fallback to the default implementation.

            //// When calling this formatter as part of content negotiation the content negotiator will always
            //// pick a non null media type. In case the user creates a new ObjectContent<T> and doesn't pass in a
            //// media type, we delegate to the base class to rely on the default behavior. It's the user's
            //// responsibility to pass in the right media type.
            //var mediaType = context.SelectedContentType;
            //if (mediaType != null)
            //{
            //    if (mediaType.MediaType.Equals("application/json", StringComparison.OrdinalIgnoreCase) &&
            //        !mediaType.Parameters.Any(p => p.Name.Equals("odata.metadata", StringComparison.OrdinalIgnoreCase)))
            //    {
            //        mediaType.Parameters.Add(new NameValueHeaderValue("odata.metadata", "minimal"));
            //    }
            //}
            //else
            //{
            //    // This is the case when a user creates a new ObjectContent<T> passing in a null mediaType
            //    base.WriteResponseHeaders(context);
            //}

            //// In general, in Web API we pick a default charset based on the supported character sets
            //// of the formatter. However, according to the OData spec, the service shouldn't be sending
            //// a character set unless explicitly specified, so if the client didn't send the charset we chose
            //// we just clean it.
            //if (headers.ContentType != null &&
            //    !Request.Headers.AcceptCharset
            //        .Any(cs => cs.Value.Equals(headers.ContentType.CharSet, StringComparison.OrdinalIgnoreCase)))
            //{
            //    headers.ContentType.CharSet = String.Empty;
            //}

            response.Headers.Append(
                ODataProperties.ODataServiceVersionHeader,
                ODataUtils.ODataVersionToString(ODataProperties.DefaultODataVersion));

            base.WriteResponseHeaders(context);
        }
Esempio n. 15
0
        /// <inheritdoc/>
        public override void SetDefaultContentHeaders(Type type, HttpContentHeaders headers, MediaTypeHeaderValue mediaType)
        {
            // Determine the content type or let base class handle it.
            MediaTypeHeaderValue newMediaType = null;

            if (ODataOutputFormatterHelper.TryGetContentHeader(type, mediaType, out newMediaType))
            {
                headers.ContentType = newMediaType;
            }
            else
            {
                // This is the case when a user creates a new ObjectContent<T> passing in a null mediaType
                base.SetDefaultContentHeaders(type, headers, mediaType);
            }

            // Set the character set.
            IEnumerable <string> acceptCharsetValues = Request.Headers.AcceptCharset.Select(cs => cs.Value);

            string newCharSet = String.Empty;

            if (ODataOutputFormatterHelper.TryGetCharSet(headers.ContentType, acceptCharsetValues, out newCharSet))
            {
                headers.ContentType.CharSet = newCharSet;
            }

            // Add version header.
            headers.TryAddWithoutValidation(
                ODataVersionConstraint.ODataServiceVersionHeader,
                ODataUtils.ODataVersionToString(ResultHelpers.GetODataResponseVersion(Request)));

            // Add Preference-Applied headers
            var responseMessage = ODataOutputFormatterHelper.PrepareResponseMessage(
                new WebApiRequestMessage(Request),
                new WebApiRequestHeaders(Request.Headers),
                (services) => ODataMessageWrapperHelper.Create(null, headers, services));

            foreach (var header in responseMessage.Headers)
            {
                if (!headers.Contains(header.Key))
                {
                    headers.TryAddWithoutValidation(header.Key, header.Value);
                }
            }
        }
        /// <inheritdoc/>
        public async override Task ExecuteResultAsync(ActionContext context)
        {
            if (context == null)
            {
                throw Error.ArgumentNull(nameof(context));
            }

            HttpRequest   request  = context.HttpContext.Request;
            HttpResponse  response = context.HttpContext.Response;
            IActionResult result   = GetInnerActionResult(request);
            Uri           location = GenerateLocationHeader(request);

            response.Headers["Location"] = location.AbsoluteUri;
            // Since AddEntityId relies on the response, make sure to execute the result
            // before calling AddEntityId() to ensure the response code is set correctly.
            await result.ExecuteResultAsync(context).ConfigureAwait(false);

            ResultHelpers.AddEntityId(response, () => GenerateEntityId(request));
            ResultHelpers.AddServiceVersion(response, () => ODataUtils.ODataVersionToString(ResultHelpers.GetODataResponseVersion(request)));
        }
Esempio n. 17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ODataBatchContent"/> class.
        /// </summary>
        /// <param name="responses">The batch responses.</param>
        /// <param name="requestContainer">The dependency injection container for the request.</param>
        /// <param name="contentType">The response content type.</param>
        public ODataBatchContent(IEnumerable <ODataBatchResponseItem> responses, IServiceProvider requestContainer, string contentType)
        {
            Responses = responses ?? throw Error.ArgumentNull(nameof(responses));

            _requestContainer = requestContainer;
            _writerSettings   = requestContainer.GetService <ODataMessageWriterSettings>() ?? new ODataMessageWriterSettings();

            // Set the Content-Type header for existing batch formats
            if (contentType == null)
            {
                contentType = string.Format(
                    CultureInfo.InvariantCulture, "multipart/mixed;boundary=batchresponse_{0}", Guid.NewGuid());
            }

            Headers = new HeaderDictionary();
            Headers["Content-Type"] = contentType;
            ODataVersion version = _writerSettings.Version ?? ODataVersionConstraint.DefaultODataVersion;

            Headers.Add(ODataVersionConstraint.ODataServiceVersionHeader, ODataUtils.ODataVersionToString(version));
        }
Esempio n. 18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ODataBatchContent"/> class.
        /// </summary>
        /// <param name="responses">The batch responses.</param>
        /// <param name="writerSettings">The <see cref="ODataMessageWriterSettings"/>.</param>
        public ODataBatchContent(IEnumerable <ODataBatchResponseItem> responses, ODataMessageWriterSettings writerSettings)
        {
            if (responses == null)
            {
                throw Error.ArgumentNull("responses");
            }
            if (writerSettings == null)
            {
                throw Error.ArgumentNull("writerSettings");
            }

            Responses           = responses;
            _writerSettings     = writerSettings;
            Headers.ContentType = MediaTypeHeaderValue.Parse(String.Format(CultureInfo.InvariantCulture, "multipart/mixed;boundary=batchresponse_{0}", Guid.NewGuid()));
            ODataVersion version = _writerSettings.Version ?? HttpRequestMessageProperties.DefaultODataVersion;

            Headers.TryAddWithoutValidation(HttpRequestMessageProperties.ODataServiceVersionHeader, ODataUtils.ODataVersionToString(version));
        }
Esempio n. 19
0
        internal static string GetVersionString(HttpRequestMessage request)
        {
            ODataVersion?serviceVersion = request.ODataProperties().ODataServiceVersion;

            return(ODataUtils.ODataVersionToString(serviceVersion ?? ODataVersionConstraint.DefaultODataVersion));
        }
Esempio n. 20
0
 public void SetDataServiceVersionHeaderTest()
 {
     TestSetHeader("DataServiceVersion", ODataUtils.ODataVersionToString(ODataVersion.V3));
 }
Esempio n. 21
0
 internal static string GetVersionString(HttpRequest request)
 {
     return(ODataUtils.ODataVersionToString(request.ODataServiceVersion() ?? ODataVersionConstraint.DefaultODataVersion));
 }
Esempio n. 22
0
        public void ExecuteBaseballStatsRequest(IEdmModel model, string fileName)
        {
            //we are going to create a GET request to the OData Netflix Catalog
            HTTPClientRequestMessage message = new HTTPClientRequestMessage("http://baseball-stats.info/OData/baseballstats.svc/");

            message.SetHeader("Accept", "application/atom+xml");
            message.SetHeader("DataServiceVersion", ODataUtils.ODataVersionToString(ODataVersion.V2));
            message.SetHeader("MaxDataServiceVersion", ODataUtils.ODataVersionToString(ODataVersion.V2));

            //create a simple text file to write the response to and create a text writer
            string filePath = @".\out\" + fileName + ".txt";

            using (StreamWriter outputWriter = new StreamWriter(filePath))
            {
                //use an indented text writer for readability
                this.writer = new IndentedTextWriter(outputWriter, "  ");

                //issue the request and get the response as an ODataMessage. Create an ODataMessageReader over the response
                //we will use the model when creating the reader as this will tell the library to validate when parsing
                using (ODataMessageReader messageReader = new ODataMessageReader(message.GetResponse(),
                                                                                 new ODataMessageReaderSettings(), model))
                {
                    //create a feed reader
                    ODataReader reader = messageReader.CreateODataFeedReader();
                    while (reader.Read())
                    {
                        switch (reader.State)
                        {
                        case ODataReaderState.FeedStart:
                        {
                            //this is just the beginning of the feed, data will not be parsed yet
                            ODataFeed feed = (ODataFeed)reader.Item;
                            this.writer.WriteLine("ODataFeed:");
                            this.writer.Indent++;
                        }

                        break;

                        case ODataReaderState.FeedEnd:
                        {
                            //this is the end of feed state. The entire message has been read at this point
                            ODataFeed feed = (ODataFeed)reader.Item;
                            if (feed.Count != null)
                            {
                                //if there is an inlinecount value write the value out
                                this.writer.WriteLine("Count: " + feed.Count.ToString());
                            }
                            if (feed.NextPageLink != null)
                            {
                                //if there is a next link write that link as well
                                this.writer.WriteLine("NextPageLink: " + feed.NextPageLink.AbsoluteUri);
                            }

                            this.writer.Indent--;
                        }

                        break;

                        case ODataReaderState.EntryStart:
                        {
                            //this is just the start of the entry.
                            //Properties of the entity will not be parsed yet
                            ODataEntry entry = (ODataEntry)reader.Item;
                            this.writer.WriteLine("ODataEntry:");
                            this.writer.Indent++;
                        }

                        break;

                        case ODataReaderState.EntryEnd:
                        {
                            //at the point the whole entry has been read
                            //and the properties of the entity are available
                            ODataEntry entry = (ODataEntry)reader.Item;
                            this.writer.WriteLine("TypeName: " + (entry.TypeName ?? "<null>"));
                            this.writer.WriteLine("Id: " + (entry.Id ?? "<null>"));
                            if (entry.ReadLink != null)
                            {
                                this.writer.WriteLine("ReadLink: " + entry.ReadLink.AbsoluteUri);
                            }

                            if (entry.EditLink != null)
                            {
                                this.writer.WriteLine("EditLink: " + entry.EditLink.AbsoluteUri);
                            }

                            if (entry.MediaResource != null)
                            {
                                this.writer.Write("MediaResource: ");
                                this.WriteValue(entry.MediaResource);
                            }

                            this.WriteProperties(entry.Properties);

                            this.writer.Indent--;
                        }

                        break;

                        case ODataReaderState.NavigationLinkStart:
                        {
                            //navigation links have their own states.
                            //This could be an expanded link and include an entire expanded entry or feed.
                            ODataNavigationLink navigationLink = (ODataNavigationLink)reader.Item;
                            this.writer.WriteLine(navigationLink.Name + ": ODataNavigationLink: ");
                            this.writer.Indent++;
                        }

                        break;

                        case ODataReaderState.NavigationLinkEnd:
                        {
                            ODataNavigationLink navigationLink = (ODataNavigationLink)reader.Item;
                            this.writer.WriteLine("Url: " +
                                                  (navigationLink.Url == null ? "<null>" : navigationLink.Url.AbsoluteUri));
                            this.writer.Indent--;
                        }

                        break;
                        }
                    }
                }
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ODataBatchContent"/> class.
        /// </summary>
        /// <param name="responses">The batch responses.</param>
        /// <param name="requestContainer">The dependency injection container for the request.</param>
        /// <remarks>This signature uses types that are AspNet-specific.</remarks>
        public ODataBatchContent(IEnumerable <ODataBatchResponseItem> responses, IServiceProvider requestContainer)
        {
            this.Initialize(responses, requestContainer);
            Headers.ContentType = MediaTypeHeaderValue.Parse(String.Format(CultureInfo.InvariantCulture, "multipart/mixed;boundary=batchresponse_{0}", Guid.NewGuid()));
            ODataVersion version = _writerSettings.Version ?? ODataVersionConstraint.DefaultODataVersion;

            Headers.TryAddWithoutValidation(ODataVersionConstraint.ODataServiceVersionHeader, ODataUtils.ODataVersionToString(version));
        }