protected internal async override Task <Stream> OnGetResponse(HttpWebRequestMessage requestMessage, Stream requestStream)
        {
            Stream    response;
            IOdataWcf client = null;

            try
            {
                client = _channelFactory.CreateChannel();
                if (requestStream == null)
                {
                    String accept = requestMessage.GetHeader("Accept");
                    response = await client.Get(requestMessage.Url.PathAndQuery, accept);
                }
                else
                {
                    String contentType = requestMessage.GetHeader(ODataConstants.ContentTypeHeader);
                    requestStream.Position = 0;
                    OdataWcfPostResponse postResponse = await client.Post(new OdataWcfPostRequest()
                    {
                        ContentType = contentType, RequestStream = requestStream
                    });

                    response = postResponse.ResponseStream;
                }
            }
            finally
            {
                if (client != null)
                {
                    var clientChannel = (IClientChannel)client;
                    clientChannel.Close();
                }
            }
            return(response);
        }
Esempio n. 2
0
        public async Task <OdataWcfQuery> Get(String query)
        {
            IOdataWcf client = null;

            try
            {
                client = _channelFactory.CreateChannel();
                return(await client.Get(new OdataWcfQuery()
                {
                    Content = new MemoryStream(Encoding.UTF8.GetBytes(query)),
                    ContentType = OeRequestHeaders.JsonDefault.ToString()
                }));
            }
            finally
            {
                if (client != null)
                {
                    var clientChannel = (IClientChannel)client;
                    clientChannel.Close();
                }
            }
        }
Esempio n. 3
0
        protected internal async override Task <OdataWcfQuery> OnGetResponse(HttpWebRequestMessage requestMessage, Stream requestStream)
        {
            OdataWcfQuery response;
            IOdataWcf     client = null;

            try
            {
                client = _channelFactory.CreateChannel();
                if (requestStream == null || requestStream.Length == 0)
                {
                    String accept = requestMessage.GetHeader("Accept");
                    String prefer = requestMessage.GetHeader("Prefer");
                    var    query  = new MemoryStream(Encoding.UTF8.GetBytes(requestMessage.Url.PathAndQuery));
                    response = await client.Get(new OdataWcfQuery()
                    {
                        Content = query, ContentType = accept, Prefer = prefer
                    });
                }
                else
                {
                    String contentType = requestMessage.GetHeader(ODataConstants.ContentTypeHeader);
                    requestStream.Position = 0;
                    response = await client.Post(new OdataWcfQuery()
                    {
                        Content = requestStream, ContentType = contentType
                    });
                }
            }
            finally
            {
                if (client != null)
                {
                    var clientChannel = (IClientChannel)client;
                    clientChannel.Close();
                }
            }
            return(response);
        }