/// <summary>
        /// Begins the get response callback.
        /// </summary>
        /// <param name="asyncResult">The async result.</param>
        private static void BeginGetResponseCallback(IAsyncResult asyncResult)
        {
            WebResponse webResponse             = null;
            Stream      responseStream          = null;
            HttpWebRequestAsyncState asyncState = null;

            try
            {
                asyncState     = (HttpWebRequestAsyncState)asyncResult.AsyncState;
                webResponse    = asyncState.HttpWebRequest.EndGetResponse(asyncResult);
                responseStream = webResponse.GetResponseStream();
                var webRequestCallbackState = new HttpWebRequestCallbackState((HttpWebResponse)webResponse, asyncState.State);
                asyncState.ResponseCallback(webRequestCallbackState);
                responseStream.Close();
                responseStream = null;
                webResponse.Close();
                webResponse = null;
            }
            catch (Exception ex)
            {
                if (asyncState != null)
                {
                    Log.WarnFormat("Exception requesting url: {0}", ex, asyncState.HttpWebRequest.RequestUri);
                    asyncState.ResponseCallback(new HttpWebRequestCallbackState(ex, asyncState.State));
                }
                else
                {
                    Log.Warn("BeginGetResponseCallback", ex);
                    throw;
                }
            }
            finally
            {
                if (responseStream != null)
                {
                    responseStream.Close();
                }
                if (webResponse != null)
                {
                    webResponse.Close();
                }
            }
        }
        static void ProcessRequest(HttpWebRequestAsyncState asyncState)
        {
            WebResponse webResponse = null;
            Stream responseStream = null;
            try
            {
                webResponse = asyncState.HttpWebRequest.GetResponse();
                responseStream = webResponse.GetResponseStream();
                var webRequestCallbackState = new HttpWebRequestCallbackState((HttpWebResponse)webResponse, asyncState.State);
                asyncState.ResponseCallback(webRequestCallbackState);
                if (responseStream != null)
                    responseStream.Close();

                responseStream = null;
                webResponse.Close();
                webResponse = null;
            }
            catch (Exception ex)
            {
                if (asyncState != null)
                {
                    Log.WarnFormat("Exception requesting url: {0}", ex, asyncState.HttpWebRequest.RequestUri);
                    asyncState.ResponseCallback(new HttpWebRequestCallbackState(ex, asyncState.State));
                }
                else
                {
                    Log.Warn("BeginGetResponseCallback", ex);
                    throw;
                }
            }
            finally
            {
                if (responseStream != null)
                    responseStream.Close();
                if (webResponse != null)
                    webResponse.Close();
            }
        }