I keep getting the following error message when trying to make an SSL Connection via VB.NET's WebRequest:

The underlying connection was closed: Could not establish trust relationship with remote server.

VB Code:
  1. Private Function SendXML(ByVal xml As String) As String
  2.  
  3.         Dim aURL As String
  4.  
  5.         aURL = "https://www.site.com:10027"
  6.  
  7.         Dim wr As HttpWebRequest = Net.WebRequest.Create(aURL)
  8.  
  9.         Dim cert As System.Security.Cryptography.X509Certificates.X509Certificate
  10.         cert = System.Security.Cryptography.X509Certificates.X509Certificate.CreateFromSignedFile("C:\cert\ca.cer")
  11.         wr.ClientCertificates.Add(cert)
  12.  
  13.         wr.ContentType = "text/xml"
  14.         wr.KeepAlive = False
  15.  
  16.         wr.Method = "POST"
  17.  
  18.         Dim sw As StreamWriter
  19.  
  20.         Try
  21.             sw = New StreamWriter(wr.GetRequestStream())
  22.             sw.Flush()
  23.             sw.AutoFlush = True
  24.         Catch ex As Exception
  25.             Return False
  26.         End Try
  27.  
  28.         Try
  29.             sw.Write(xml)
  30.             sw.Flush()
  31.             sw.Close()
  32.  
  33.         Catch ex As Exception
  34.             Return False
  35.         End Try
  36.  
  37.         wr.Timeout = 900000
  38.         Dim wres As HttpWebResponse = wr.GetResponse
  39.  
  40.         Dim s As IO.Stream
  41.         s = wres.GetResponseStream
  42.  
  43.         Dim sr As IO.StreamReader
  44.         sr = New IO.StreamReader(s)
  45.  
  46.         Return sr.ReadToEnd
  47.  
  48.     End Function