Search code examples
.netazurecertificatex509certificate

Certificate issue when Connecting with Azure Service Management API


I am getting an issue while fetching the list of hosted services. My code is as below:

 string requestUrl = "https://management.core.windows.net/" + SubscriptionID + "/services/hostedservices";

        string ReturnBody = string.Empty;
        WebResponse resp = null;
        try
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
            NameValueCollection RequestHeaders = new NameValueCollection();
            RequestHeaders.Add("x-ms-version", x_ms_version);
            X509Certificate cert = X509Certificate.CreateFromCertFile(CertificatePath);
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestUrl);
            request.Method = "GET";
            request.ClientCertificates.Add(cert);
            request.KeepAlive = false;
            request.ProtocolVersion = HttpVersion.Version10;
            if (RequestHeaders != null)
                request.Headers.Add(RequestHeaders);
            resp = request.GetResponse();              
        }
        catch (WebException webEx)
        {
            //ERROR: The request was aborted: Could not create SSL/TLS secure channel.” error.
        }
        catch (Exception excep)
        {
            
        }
        finally
        {
            if (resp != null) { resp.Close(); }
            resp = null;
        }  

While running above code I am getting:

"The request was aborted: Could not create SSL/TLS secure channel"

One strange point regarding this is that same code is working fine in one of my WPF application, but giving an error in Web Application. So, it may issue of IIS security, I have made unsuccessful attempt by giving permission to everyone for that folder.


Solution

  • I believe I responded to this question on MSDN forums: http://social.msdn.microsoft.com/Forums/en-US/windowsazuredata/thread/5e6a2cfd-c2b6-4880-a79c-4bf39f4d7ca8/#b427afb6-d68f-4591-8466-870e791b43c9

    Did you try out the suggestion I made? What's the error you're getting even after that.

    Gaurav