/// <summary>Creates a credentials object for the given connection.</summary>
        /// <param name="source">The source.</param>
        /// <returns>The credentials.</returns>
        public static ICredentials CreateCredentials(this HttpClientConnection source)
        {
            if (source.UseServerCredentials)
            {
                return(CredentialCache.DefaultCredentials);
            }

            if (!String.IsNullOrWhiteSpace(source.ServerDomain))
            {
                return(new NetworkCredential(source.ServerUserName, source.GetServerPassword(), source.ServerDomain));
            }
            else
            {
                return(new NetworkCredential(source.ServerUserName, source.GetServerPassword()));
            }
        }
        /// <summary>Sets the client credentials on a WCF client.</summary>
        /// <typeparam name="T">The service interface.</typeparam>
        /// <param name="source">The client.</param>
        /// <param name="connection">The HTTP connection.</param>
        /// <remarks>
        /// Both Windows and basic credentials are supported.
        /// </remarks>
        public static void SetClientCredentials <T> (this ClientBase <T> source, HttpClientConnection connection) where T : class
        {
            //Windows
            if (connection.UseWindowsCredentials())
            {
                var creds = source.ClientCredentials.Windows;

                creds.ClientCredential.UserName = connection.ServerUserName;
                creds.ClientCredential.Password = connection.GetServerPassword();
                creds.ClientCredential.Domain   = connection.ServerDomain;
            }
            else if (!String.IsNullOrWhiteSpace(connection.ServerUserName))
            {
                var creds = source.ClientCredentials;

                creds.UserName.UserName = connection.ServerUserName;
                creds.UserName.Password = connection.GetServerPassword();
            }
            ;
        }