/// <summary>
        /// Sends the asynchronous request to the server.
        /// </summary>
        /// <param name="request">The request to be send.</param>
        /// <param name="cancellationToken">The operation cancellation token.</param>
        /// <returns>The Task representing the asynchronous operation.</returns>
        protected override async Task <HttpResponseMessage> SendAsync(
            HttpRequestMessage request,
            CancellationToken cancellationToken)
        {
            try
            {
                // Validate that the object is no disposed
                this.EnsureNotDisposed();

                // Execute the request
                var convertedRequest =
                    await WindowsHttpMessageHandler.ConvertRequest(request, cancellationToken).ConfigureAwait(false);

                var response =
                    await this.client.SendRequestAsync(convertedRequest).AsTask(cancellationToken).ConfigureAwait(false);

                var convertedResponse =
                    await WindowsHttpMessageHandler.ConvertResponse(response, cancellationToken).ConfigureAwait(false);

                // Return the converted response
                return(convertedResponse);
            }
            catch (Exception ex)
            {
                throw new WebException(ex.Message, ex, WebExceptionStatus.ConnectFailure, null);
            }
        }
        /// <summary>
        /// Converts the received response message.
        /// </summary>
        /// <param name="response">The request message to be transformed.</param>
        /// <param name="cancellationToken">The operation cancellation token.</param>
        /// <returns>The Task representing the asynchronous operation.</returns>
        private static async Task <HttpResponseMessage> ConvertResponse(
            Windows.Web.Http.HttpResponseMessage response,
            CancellationToken cancellationToken)
        {
            // Convert the response
            var converted = new HttpResponseMessage((HttpStatusCode)(int)response.StatusCode)
            {
                ReasonPhrase   = response.ReasonPhrase,
                RequestMessage = await WindowsHttpMessageHandler
                                 .ConvertRequest(response.RequestMessage, cancellationToken)
                                 .ConfigureAwait(false),
                Content = await WindowsHttpMessageHandler.ConvertContent(response.Content, cancellationToken)
                          .ConfigureAwait(false),
                Version = WindowsHttpMessageHandler.GetVersion(response.Version)
            };

            // Copy headers
            foreach (var header in response.Headers)
            {
                converted.Headers.TryAddWithoutValidation(header.Key, header.Value);
            }

            // Return the converted message
            return(converted);
        }
        /// <summary>
        /// Converts the request message that was send.
        /// </summary>
        /// <param name="request">The request message to be transformed.</param>
        /// <param name="cancellationToken">The operation cancellation token.</param>
        /// <returns>The Task representing the asynchronous operation.</returns>
        private static async Task <HttpRequestMessage> ConvertRequest(
            Windows.Web.Http.HttpRequestMessage request,
            CancellationToken cancellationToken)
        {
            // Convert the request message
            var converted = new HttpRequestMessage
            {
                Method     = new HttpMethod(request.Method.Method),
                RequestUri = request.RequestUri,
                Content    = await WindowsHttpMessageHandler.ConvertContent(request.Content, cancellationToken)
                             .ConfigureAwait(false)
            };

            // Copy request headers
            foreach (var header in request.Headers)
            {
                converted.Headers.TryAddWithoutValidation(header.Key, header.Value);
            }

            // Copy request properties
            foreach (var prop in request.Properties)
            {
                converted.Properties.Add(prop);
            }

            // Return the transformed request
            return(converted);
        }
        /// <summary>
        /// Converts the request message to be send.
        /// </summary>
        /// <param name="request">The request message to be transformed.</param>
        /// <param name="cancellationToken">The operation cancellation token.</param>
        /// <returns>The Task representing the asynchronous operation.</returns>
        private static async Task <Windows.Web.Http.HttpRequestMessage> ConvertRequest(
            HttpRequestMessage request,
            // ReSharper disable once UnusedParameter.Local
            CancellationToken cancellationToken)
        {
            // Create the request message
            var converted = new Windows.Web.Http.HttpRequestMessage
            {
                Method     = new Windows.Web.Http.HttpMethod(request.Method.Method),
                Content    = await WindowsHttpMessageHandler.ConvertContent(request.Content).ConfigureAwait(false),
                RequestUri = request.RequestUri
            };

            // Copy request headers
            WindowsHttpMessageHandler.CopyHeaders(request.Headers, converted.Headers);

            // Copy request properties
            foreach (var property in request.Properties)
            {
                converted.Properties.Add(property);
            }

            // Return the transformed request
            return(converted);
        }
        /// <summary>
        /// Converts the convent from System.Net.Http.HttpContent to Windows.Web.Http.IHttpContent.
        /// </summary>
        /// <param name="content">The System.Net.Http.HttpContent to convert.</param>
        /// <returns>Converted Windows.Web.Http.IHttpContent.</returns>
        private static async Task <Windows.Web.Http.IHttpContent> ConvertContent(HttpContent content)
        {
            // If no content to convert
            if (content == null)
            {
                return(null);
            }

            // Convert the content
            var stream = await content.ReadAsStreamAsync().ConfigureAwait(false);

            var converted = new Windows.Web.Http.HttpStreamContent(stream.AsInputStream());

            // Copy content headers
            WindowsHttpMessageHandler.CopyHeaders(content.Headers, converted.Headers);

            // Return the converted content
            return(converted);
        }