private void CreateAndReadUnlimitedResponseMessageWithFeed(string startingString, string cycleString)
            {
                var responseMessage = new ODataUnlimitedResponseMessage(startingString, cycleString);

                responseMessage.SetHeader("Content-Type", "application/atom+xml");
                responseMessage.SetHeader("DataServiceVersion", "3.0");

                var readLimitReached = false;

                try
                {
                    using (var messageReader = new ODataMessageReader(responseMessage))
                    {
                        var feedReader = messageReader.CreateODataFeedReader();
                        while (feedReader.Read())
                        {
                            switch (feedReader.State)
                            {
                            case ODataReaderState.FeedStart:
                                Console.WriteLine("FeedStart: " + (ODataFeed)feedReader.Item);
                                break;

                            case ODataReaderState.FeedEnd:
                                Console.WriteLine("FeedEnd: " + (ODataFeed)feedReader.Item);
                                break;

                            case ODataReaderState.EntryStart:
                                Console.WriteLine("EntryStart: " + (ODataEntry)feedReader.Item);
                                break;

                            case ODataReaderState.EntryEnd:
                                Console.WriteLine("EntryEnd: " + (ODataEntry)feedReader.Item);
                                break;

                            default:
                                Console.WriteLine("ODataItem: " + feedReader.Item);
                                break;
                            }
                        }
                    }
                }
                catch (ODataException ex)
                {
                    if (ex.Message.StartsWith("The maximum number of bytes allowed to be read from the stream has been exceeded."))
                    {
                        readLimitReached = true;
                    }
                    else
                    {
                        throw;
                    }
                }

                if (!readLimitReached)
                {
                    throw new InvalidOperationException("Expecting exception, but it was not thrown.");
                }
            }
Exemple #2
0
            private void CreateAndReadUnlimitedResponseMessageWithEntry(string startingString, string cycleString)
            {
                var model = this.GetModel();

                if (model != null)
                {
                    var responseMessage = new ODataUnlimitedResponseMessage(startingString, cycleString);
                    responseMessage.SetHeader("Content-Type", "application/json");
                    responseMessage.SetHeader("DataServiceVersion", "3.0");

                    var readLimitReached = false;
                    try
                    {
                        using (var messageReader = new ODataMessageReader(responseMessage, new ODataMessageReaderSettings(), model))
                        {
                            var entryReader = messageReader.CreateODataEntryReader();
                            entryReader.Read();
                            var result = entryReader.Item;
                            Console.WriteLine(result);
                        }
                    }
                    catch (ODataException ex)
                    {
                        if (ex.Message.StartsWith("The maximum number of bytes allowed to be read from the stream has been exceeded."))
                        {
                            readLimitReached = true;
                        }
                        else
                        {
                            throw;
                        }
                    }

                    if (!readLimitReached)
                    {
                        throw new InvalidOperationException("Expecting exception, but it was not thrown.");
                    }
                }
            }
            private void CreateAndReadResponseMessageWithFeed(string startingString, string cycleString)
            {
                var model = this.GetModel();
                if (model != null)
                {
                    var responseMessage = new ODataUnlimitedResponseMessage(startingString, cycleString);
                    responseMessage.SetHeader("Content-Type", "application/json");
                    responseMessage.SetHeader("DataServiceVersion", "3.0");

                    var readLimitReached = false;
                    try
                    {

                        using (var messageReader = new ODataMessageReader(responseMessage, new ODataMessageReaderSettings(), model))
                        {
                            var feedReader = messageReader.CreateODataFeedReader();
                            while (feedReader.Read())
                            {
                                switch (feedReader.State)
                                {
                                    case ODataReaderState.FeedStart:
                                        Console.WriteLine("FeedStart: " + (ODataFeed)feedReader.Item);
                                        break;

                                    case ODataReaderState.FeedEnd:
                                        Console.WriteLine("FeedEnd: " + (ODataFeed)feedReader.Item);
                                        break;

                                    case ODataReaderState.EntryStart:
                                        Console.WriteLine("EntryStart: " + (ODataEntry)feedReader.Item);
                                        break;

                                    case ODataReaderState.EntryEnd:
                                        Console.WriteLine("EntryEnd: " + (ODataEntry)feedReader.Item);
                                        break;

                                    default:
                                        Console.WriteLine("ODataItem: " + feedReader.Item);
                                        break;
                                }
                            }
                        }
                    }
                    catch (ODataException ex)
                    {
                        if (ex.Message.StartsWith("The maximum number of bytes allowed to be read from the stream has been exceeded."))
                        {
                            readLimitReached = true;
                        }
                        else
                        {
                            throw;
                        }
                    }

                    if (!readLimitReached)
                    {
                        throw new InvalidOperationException("Expecting exception, but it was not thrown.");
                    }
                }
            }
            private void CreateAndReadUnlimitedResponseMessageWithEntry(string startingString, string cycleString)
            {
                var model = this.GetModel();
                if (model != null)
                {
                    var responseMessage = new ODataUnlimitedResponseMessage(startingString, cycleString);
                    responseMessage.SetHeader("Content-Type", "application/json");
                    responseMessage.SetHeader("DataServiceVersion", "3.0");

                    var readLimitReached = false;
                    try
                    {

                        using (var messageReader = new ODataMessageReader(responseMessage, new ODataMessageReaderSettings(), model))
                        {
                            var entryReader = messageReader.CreateODataEntryReader();
                            entryReader.Read();
                            var result = entryReader.Item;
                            Console.WriteLine(result);
                        }
                    }
                    catch (ODataException ex)
                    {
                        if (ex.Message.StartsWith("The maximum number of bytes allowed to be read from the stream has been exceeded."))
                        {
                            readLimitReached = true;
                        }
                        else
                        {
                            throw;
                        }
                    }

                    if (!readLimitReached)
                    {
                        throw new InvalidOperationException("Expecting exception, but it was not thrown.");
                    }
                }
            }