locked
Exception to code RRS feed

  • Question

  • User364663285 posted

    Hi,
    Any help to stacktrace below:

    Error received while making request: The request was aborted: Could not create SSL/TLS secure channel. at MaxMind.GeoIP2.Http.SyncClient.Get(Uri uri) at MaxMind.GeoIP2.WebServiceClient.Execute[T](String type, IPAddress ipAddress) at MaxMind.GeoIP2.WebServiceClient.Country(IPAddress
    
    

    with these code?

                        using (var client = new WebServiceClient(???, "???"))
                        {
                            var response = client.Country(IPAddress);
    
                            SqlCommand cmd3g = new SqlCommand("... "',getdate()) ", conn3g);
    
                            cmd3g.ExecuteNonQuery();
    

    Monday, January 20, 2020 7:46 AM

All replies

  • User-1780421697 posted

    In .Net 4.5 :

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

    Its about using TLS version.

    Monday, January 20, 2020 10:13 AM
  • Monday, January 20, 2020 10:14 AM
  • User283571144 posted

    Hi wmec,

    In the .NET Framework 4.7 , the "ServicePointManager.SecurityProtocol" has been set to defaults security protocal configured by the operating system. Your application may run differently based on the OS it's run on.  

    For example, Windows 7 SP1 uses TLS 1.0 while Windows 8 and Windows 10 use TLS 1.2. Details, you could refer to this article.

    In your code, the exception is threw because of the old version of the .NET Framework (4.0 or 4.5) in which you have to set the security protocal properly based on the OS of your computer.I tried the MaxMind.GeoIP2 package to find the location with a given IP Address in .NET Framework 4.5 with TLS 1.2 (Mine OS is Window 10) and make it working.

    [WebMethod]
            public string GetLocation(string IPAddress)
            {
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                using (var client = new WebServiceClient(accountID, "license key"))
                {
                    var response = client.Country(IPAddress);
                    return response.Country.IsoCode + response.Country.Name + response.Country.Names["en-us"];
                }
            }
    

    Result:

    Best Regards,

    Brando

    Tuesday, January 21, 2020 9:55 AM
  • User364663285 posted

    Thanks to all.

    Brando,
    Does it mean I should ensure server is with .Net framework 4.7?

    Wednesday, January 22, 2020 6:22 AM
  • User283571144 posted

    Hi wmec,

    The .NET framework version 3.5 SP1 and earlier versions did not provide support for applications to use Transport Layer Security (TLS) System Default Versions as a cryptographic protocol. This update enables the use of TLS v1.2 in the .NET Framework 3.5 SP1.

    So, it is not mandatory to ensure that .NET Framework is 4.7 as you can configure the SecurityProtocol after the .NET Framework 3.5.

    However, I recommend you targets the .NETFramework 4.7 on your apps since you don't need to specify the TLS version for which the OS will do. This will bring some advantages:

    It automatically takes advantage of new protocols added in the future, such as TLS 1.3.
    The OS blocks protocols that are discovered not to be secure. 
    Otherwise, you should choose to manually code for setting the value of ServicePointManager.SecurityProtocol to proper protocol based on your OS version.

    Best Regards,

    Brando

    Thursday, January 23, 2020 6:18 AM
  • User364663285 posted

    Hi,
    I set up .Net Framework 4.7 and re-publish the project but same problem persists. What to do with securityprotocol?

    Friday, January 24, 2020 8:27 AM