0

Cannot access https url from c# code. trying to access a https://blabla url and access the get method. this is SOAP generated c# class from wsdl. it works from SOAP UI without any problem but doesn't work from the code.i get the error as "Could not create SSL/TLS secure channel"

Isham
  • 37
  • 7

2 Answers2

1

I've had this so many times.

You need to set the SecurityProtocol before executing the method. The HTTP Request you are trying to make expects the request to be sent using Transport Layer Security.

To support TLS in your request, use the following code (this sets it to Tls 1.2) before firing the HTTP Request: System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

You can find more information on the different settings from this URL: https://learn.microsoft.com/en-us/dotnet/api/system.net.securityprotocoltype?view=netcore-3.0

If you find that this enum does not exist (because you are using an older version of .NET), you can use the enum integer value from the link above. This example supports Tls 1.2. System.Net.ServicePointManager.SecurityProtocol = (System.Net.SecurityProtocolType)3072;

David Grace
  • 141
  • 4
  • I tried this too but no luck, any other suggestions. – Isham Aug 25 '19 at 13:14
  • Can you provide an example of what you've done so far? – David Grace Aug 25 '19 at 13:57
  • ` using (var client = new WebService()) { data = new JavaScriptSerializer().Deserialize>(client.GetLookupDetails()); TempData["lookupData"] = data; } ` the url "https://blabla.asmx" the proxy class is generated from wsdl.exe @david-grace – Isham Aug 26 '19 at 05:09
0

I'm not sure then, unless the following works. But you mentioned that you already tried setting the SecurityProtocol enum. It might be that your webservice connection expects to be supported with TLS 1.3.

Try the following code and uncomment each line that begins with System.Net.ServicePointManager.SecurityProtocol individually to see if it resolves your issue:

            // Uncomment one of these four to see if it works
            //System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
            //System.Net.ServicePointManager.SecurityProtocol = (System.Net.SecurityProtocolType)3072;
            //System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls13;
            //System.Net.ServicePointManager.SecurityProtocol = (System.Net.SecurityProtocolType)12288;

            using (var client = new WebService())
            {
                data = new JavaScriptSerializer().Deserialize<List<LookupModel>>(client.GetLookupDetails());
                TempData["lookupData"] = data;
            }
David Grace
  • 141
  • 4