0

I am posting xml from a .net application to a third party web service but receive a "could not create SSL/TLS secure channel" error. When I make the request with soapUI it works fine and i get a response. But cant seem to get it from my .net console app.

I have tried setting the security to tls1 and tls12 but still no success. The certificate is installed on the server from which i am making these requests.

Is there anyone who has managed to solve this issue?

Here is a sample of my code

 System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://thirdPartyURL/cgi-bin/XmlProc");
byte[] bytes;
             bytes = System.Text.Encoding.ASCII.GetBytes("myXML");
            request.ContentType = "text/xml; encoding='utf-8'"; 
            request.ContentLength = bytes.Length;
            request.Method = "POST";                
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
            Stream requestStream = request.GetRequestStream();
            requestStream.Write(bytes, 0, bytes.Length);
            requestStream.Close();
            HttpWebResponse response;
            response = (HttpWebResponse)request.GetResponse();
Linkz
  • 51
  • 1
  • 3
  • 9
  • 1
    does your machine have tls1.2 enabled in the registry? check my answer to similar question here https://stackoverflow.com/questions/45382254/update-net-web-service-to-use-tls-1-2/45441341#45441341 – Artem Jan 24 '18 at 10:17
  • 1
    Lat night I answered a very similar question ( https://stackoverflow.com/questions/48412795/how-to-send-fix-logon-message-with-c-sharp-net-core-2-0-to-gdax#comment83816492_48412795). Since it is working with SOAP. I would use a sniffer like wireshark or fiddler and compare the SOAP and you APP. You are using a HTTPWebRequest so usually either a Header is missing and/or one is using http 1.0 and the other http 1.1. – jdweng Jan 24 '18 at 10:44
  • If you want TLS1.2 *don't* set the other flags – Panagiotis Kanavos Jan 25 '18 at 12:59

1 Answers1

0

Fixed this by doing the following:

  1. Changing the .Net Framework to 4.5
  2. Installing the certificate in the "Third-Party Root Authorities" store
  3. Added this line of code before making the request in my app

    System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

  4. Ran the application on a windows server 2012 instead of windows server 2008. It might be a case that windows server 2008 does not support TLS v1.2

Linkz
  • 51
  • 1
  • 3
  • 9
  • 4.5 is no longer supported. The earliest supported version is 4.5.2. After 4.6 TLS 1.2 is the default so you don't have to do anything, unless you want to *prevent* connections with anything less than TLS1.2 – Panagiotis Kanavos Jan 25 '18 at 12:58