private static void ProcessGetResponseCompletion(IAsyncResult iar)
 {
     HttpClientTransportSink.AsyncHttpClientRequestState asyncState = (HttpClientTransportSink.AsyncHttpClientRequestState)iar.AsyncState;
     try
     {
         asyncState.RequestStream.Close();
         HttpWebResponse response   = null;
         HttpWebRequest  webRequest = asyncState.WebRequest;
         try
         {
             response = (HttpWebResponse)webRequest.EndGetResponse(iar);
         }
         catch (WebException exception)
         {
             HttpClientTransportSink.ProcessResponseException(exception, out response);
         }
         asyncState.WebResponse = response;
         ChunkedMemoryStream target = new ChunkedMemoryStream(CoreChannel.BufferPool);
         asyncState.ActualResponseStream = target;
         StreamHelper.BeginAsyncCopyStream(response.GetResponseStream(), target, true, false, true, false, s_processAsyncCopyRequestStreamCompletion, asyncState);
     }
     catch (Exception exception2)
     {
         asyncState.SinkStack.DispatchException(exception2);
     }
 }
 private static void ProcessAsyncCopyRequestStreamCompletion(IAsyncResult iar)
 {
     HttpClientTransportSink.AsyncHttpClientRequestState asyncState = (HttpClientTransportSink.AsyncHttpClientRequestState)iar.AsyncState;
     try
     {
         StreamHelper.EndAsyncCopyStream(iar);
         asyncState.WebRequest.BeginGetResponse(s_processGetResponseCompletionCallback, asyncState);
     }
     catch (Exception exception)
     {
         asyncState.RetryOrDispatchException(exception);
     }
 }
 private static void ProcessGetRequestStreamCompletion(IAsyncResult iar)
 {
     HttpClientTransportSink.AsyncHttpClientRequestState asyncState = (HttpClientTransportSink.AsyncHttpClientRequestState)iar.AsyncState;
     try
     {
         HttpWebRequest webRequest    = asyncState.WebRequest;
         Stream         requestStream = asyncState.RequestStream;
         Stream         target        = webRequest.EndGetRequestStream(iar);
         StreamHelper.BeginAsyncCopyStream(requestStream, target, false, true, false, true, s_processAsyncCopyRequestStreamCompletionCallback, asyncState);
     }
     catch (Exception exception)
     {
         asyncState.RetryOrDispatchException(exception);
     }
 }
 private static void ProcessAsyncCopyResponseStreamCompletion(IAsyncResult iar)
 {
     HttpClientTransportSink.AsyncHttpClientRequestState asyncState = (HttpClientTransportSink.AsyncHttpClientRequestState)iar.AsyncState;
     try
     {
         StreamHelper.EndAsyncCopyStream(iar);
         HttpWebResponse   webResponse          = asyncState.WebResponse;
         Stream            actualResponseStream = asyncState.ActualResponseStream;
         ITransportHeaders headers = HttpClientTransportSink.CollectResponseHeaders(webResponse);
         asyncState.SinkStack.AsyncProcessResponse(headers, actualResponseStream);
     }
     catch (Exception exception)
     {
         asyncState.SinkStack.DispatchException(exception);
     }
 }