Пример #1
0
        private void ResponseAcquired(IAsyncResult ar)
        {
            var state = (ClientOperationState)ar.AsyncState;

            try
            {
                var response      = (HttpWebResponse)state.Request.EndGetResponseExtended(ar);
                var networkStream = response.GetResponseStream();

                if (networkStream == null)
                {
                    throw new ArgumentNullException("networkStream", "Response stream was null");
                }

                state.Response     = new HttpResponse(response);
                state.InputStream  = networkStream;
                state.OutputStream = new MemoryStream();

                var copier = new AsyncStreamCopier <ClientOperationState>(state.InputStream, state.OutputStream, state);
                copier.Completed += ResponseRead;
                copier.Start();
            }
            catch (Exception e)
            {
                state.DisposeIOStreams();
                state.OnError(e);
            }
        }
Пример #2
0
        private void GotRequestStream(IAsyncResult ar)
        {
            var state = (ClientOperationState)ar.AsyncState;

            try
            {
                var networkStream = state.Request.EndGetRequestStream(ar);
                state.OutputStream = networkStream;
                var copier = new AsyncStreamCopier <ClientOperationState>(state.InputStream, networkStream, state);
                copier.Completed += RequestWrote;
                copier.Start();
            }
            catch (Exception e)
            {
                state.DisposeIOStreams();
                state.OnError(e);
            }
        }