Toolkit source fix for "trust relationship error"

Aug 14, 2008 at 8:21 AM
The Bin version still does not work at all for me. It still fires a "System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel"-Exception. I am using Vista64/IIS7/VS2008 with the latest toolkit bits. Because the remote certificate of the https connection is rendered invalid I need to progammatically intercept the certificate validation and make it return "true".
To fix this I needed to alter the toolkit source and add the following (bold):

internal static WebResponse postRequest(string requestUrl, string postString)
        {
            var webRequest = WebRequest.Create(requestUrl);
            webRequest.Method = "POST";
            webRequest.ContentType = "application/x-www-form-urlencoded";

            ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidation;  

            if (!String.IsNullOrEmpty(postString))
            {
                var parameterString = Encoding.ASCII.GetBytes(postString);
                webRequest.ContentLength = parameterString.Length;

                using (var buffer = webRequest.GetRequestStream())
                {
                    buffer.Write(parameterString, 0, parameterString.Length);
                    buffer.Close();
                }
            }

            return webRequest.GetResponse();
        }

        public static bool RemoteCertificateValidation(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            return true;
        }


Maybe it is of help for someone until this issue is fixed.
cheers,
El
Aug 21, 2008 at 2:08 AM
When I try adding that code, I get 3 errors on the RemoteCertificateValidation line, including:
"The type or namespace name 'X509Certificate' could not be found (are you missing a using directive or an assembly reference?) "

Any help?
Aug 21, 2008 at 6:37 AM
True. I use Resharper which suggests to add the missing imports itself so I forgot to mention that you need to import (using) the required bits to the class.
You are probably missing:

using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

El