/// <summary>
        /// Converts the current ConsumerRequest to an HttpWebRequest
        /// </summary>
        /// <returns>Return an HttpWebRequest with a client certificate attached.</returns>
        public override HttpWebRequest ToWebRequest()
        {
            var webReqeust = base.ToWebRequest();

            X509Certificate2 certificate = _certificateFactory.CreateCertificate();

            // Attach the certificate to the HttpWebRequest
            if (certificate != null)
            {
                webReqeust.ClientCertificates.Add(certificate);
            }

            return(webReqeust);
        }
        public static X509Certificate2 GetClientSslCertificate()
        {
            ICertificateFactory clientSslCertificateFactory = GetClientSslCertificateFactory();

            return(clientSslCertificateFactory.CreateCertificate());
        }
        public virtual HttpWebRequest ToWebRequest()
        {
            RequestDescription description = GetRequestDescription();

            var request = (HttpWebRequest)WebRequest.Create(description.Url);

            request.Timeout   = (int)TimeSpan.FromMinutes(3).TotalMilliseconds;
            request.Method    = description.Method;
            request.UserAgent = _consumerContext.UserAgent;

            if (!string.IsNullOrEmpty(AcceptsType))
            {
                request.Accept = AcceptsType;
            }

            DateTime?ifModifiedSinceDate = ParseIfModifiedSince(Context);

            if (ifModifiedSinceDate.HasValue)
            {
                request.IfModifiedSince = ifModifiedSinceDate.Value;
            }

            if (ProxyServerUri != null)
            {
                request.Proxy = new WebProxy(ProxyServerUri, false);
            }

            if (description.ContentType == Parameters.HttpFormEncoded)
            {
                request.ContentType = description.ContentType;

                using (var writer = new StreamWriter(request.GetRequestStream()))
                {
                    writer.Write(description.Body);
                }
            }
            else if (!string.IsNullOrEmpty(description.Body))
            {
                using (var writer = new StreamWriter(request.GetRequestStream()))
                {
                    writer.Write(description.Body);
                }
            }
            else if (description.RequestStream != null)
            {
                using (var requestStream = request.GetRequestStream())
                {
                    description.RequestStream.CopyTo(requestStream);
                }
            }

            if (description.Headers.Count > 0)
            {
                foreach (string key in description.Headers.AllKeys)
                {
                    request.Headers[key] = description.Headers[key];
                }
            }

            // Attach a client ssl certificate to the HttpWebRequest
            if (_clientSslCertificateFactory != null)
            {
                X509Certificate2 certificate = _clientSslCertificateFactory.CreateCertificate();

                if (certificate != null)
                {
                    request.ClientCertificates.Add(certificate);
                }
            }

            return(request);
        }