get request in batch request

Topics: OData Library
Feb 8, 2014 at 4:48 PM
i am new in odatalib and i am trying to generate batch request with get, and i am getting exception that it isnt allowed
using System.IO;
using Microsoft.Data.OData;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ODataLib
{
    internal class ResponseMessage : IODataResponseMessage
    {
        private readonly Stream stream;
        private readonly Dictionary<string, string> headers = new Dictionary<string, string>();

        public ResponseMessage(Stream stream)
        {
            this.stream = stream;
        }

        public string GetHeader(string headerName)
        {
            string value;

            return this.headers.TryGetValue(headerName, out value) ? value : null;
        }

        public void SetHeader(string headerName, string headerValue)
        {
            this.headers.Add(headerName, headerValue);
        }

        public Stream GetStream()
        {
            return this.stream;
        }

        public IEnumerable<KeyValuePair<string, string>> Headers
        {
            get { return this.headers; }
        }

        public int StatusCode { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            // Create the stream to have ODataLib write to.
            Stream stream = new MemoryStream();

            using (var messageWriter = new ODataMessageWriter(new ResponseMessage(stream)))
            {

                var batchWriter = messageWriter.CreateODataBatchWriter();
                // Write a query operation.
                var queryOperationMessage = batchWriter.CreateOperationRequestMessage(
                    "GET", new Uri("http://services.odata.org/v3/OData/OData.svc/Products(0)"));

                // Example of header modification on inner payload.
                queryOperationMessage.SetHeader(
                    "Accept", "application/json;odata=minimalmetadata");

                batchWriter.WriteEndBatch();

                stream.Seek(0, SeekOrigin.Begin);
                var streamReader = new StreamReader(stream);
                Console.Write(streamReader.ReadToEnd());
                Console.ReadKey();

            }

           
        }
    }
}