Click here to Skip to main content
15,881,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have developed one application in .net 3.5 framework and consuming web service through it using below code

In our development application it's running fine but when I have deployed it in production environment It's giving me an error. I have tested it in three different OS Windows 7, Windows Server 2008 R2 and Windows Server 2003 R2

System.NotSupportedException: The requested security protocol is not supported.

Do I need to install any additional software or patch?

I have gone through Microsoft Support[^]

But when I install this patch I am getting error "This patch is not applicable to your system"

What I have tried:

Module SslProtocolsExtensions
    Public Const Tls12 As SslProtocols = CType(&HC00, SslProtocols)
    Public Const Tls11 As SslProtocols = CType(&H300, SslProtocols)
End Module

Module SecurityProtocolTypeExtensions
    Public Const Tls12 As SecurityProtocolType = CType(SslProtocolsExtensions.Tls12, SecurityProtocolType)
    Public Const Tls11 As SecurityProtocolType = CType(SslProtocolsExtensions.Tls11, SecurityProtocolType)
    Public Const SystemDefault As SecurityProtocolType = CType(0, SecurityProtocolType)
End Module

Dim response As String
        Dim client As New WebClient()
        Dim credentials As String

        credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes("XXXX" + ":" + "XXXX"))
        client.Headers.Add("Authorization", "Basic " & credentials)
        client.Headers.Add(HttpRequestHeader.ContentType, "application/xml")
        If blnCookie Then
            client.Headers.Add(HttpRequestHeader.Cookie, strCookie)
        End If

        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls Or SecurityProtocolType.Ssl3 Or SecurityProtocolTypeExtensions.Tls11
        Try
            Dim strEaushadhiURI = "https://XXXXXXXXXXX/AMH/1031180700004"
            System.Net.ServicePointManager.ServerCertificateValidationCallback = _
  Function(se As Object, _
  cert As System.Security.Cryptography.X509Certificates.X509Certificate, _
  chain As System.Security.Cryptography.X509Certificates.X509Chain, _
  sslerror As System.Net.Security.SslPolicyErrors) True
            response = client.DownloadString(New Uri(strEaushadhiURI))
            System.Net.ServicePointManager.ServerCertificateValidationCallback = Nothing
            TextBox1.Text = response
        Catch ex As WebException
            Throw ex
        End Try
Posted
Comments
TommoDotCommo 14-Aug-18 2:00am    
What protocols does the web service support? It doesn't look like you have TLSv1.2 implemented properly, does the web service require TLSv1.2 only?
Suman Zalodiya 14-Aug-18 2:46am    
Yes, Machine on which web service is deployed allows only TLS1.2. But same code is working properly in development environment.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900