Working with SharePoint 2010 Client Object Model on an SSL enabled site

When working SharePoint 2010 Client Object Model on an SSL enabled SharePoint 2010 site, we also need to pass in the certificate and validate it for the client object model calls to work.

Below is a sample.

    1: private void button1_Click(object sender, EventArgs e)
    2: {
    3:     ClientContext context = new ClientContext("https://[sharepointserver]");
    4:     ServicePointManager.ServerCertificateValidationCallback = delegate(object sender1, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
    5:     {
    6:         bool validationResult = true;
    7:         return validationResult;
    8:     };
    9:  
   10:     ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(customXertificateValidation);            
   11:     context.ExecutingWebRequest +=new EventHandler<WebRequestEventArgs>(context_ExecutingWebRequest);
   12:  
   13:     Web web = context.Web;
   14:     context.Load(web, w => w.Title);
   15:     context.Credentials = CredentialCache.DefaultNetworkCredentials;
   16:     context.ExecuteQuery();
   17:     richTextBox1.Text = web.Title;
   18: }
   19:  
   20: static void context_ExecutingWebRequest(object sender, WebRequestEventArgs e)
   21: {
   22:  
   23:     HttpWebRequest webReq = e.WebRequestExecutor.WebRequest;
   24:     //webReq.Proxy = new WebProxy("https://[ProxyAddress]"); //Specify a proxy address if you need to
   25:     X509Certificate cert = X509Certificate.CreateFromCertFile(@"d:\test.cer");
   26:     webReq.ClientCertificates.Add(cert);
   27: }
   28:  
   29: private static bool customXertificateValidation(object sender, X509Certificate cert, X509Chain chain, System.Net.Security.SslPolicyErrors error)
   30: {
   31:     return true;
   32: }

Hope this helps!  Cheers.