5

I am connecting to a java webservice using ssl V3 from an ASP.net 2.0 web application using HttpWebRequest. When I call the GetRequestStream, I'm getting the error "Received an unexpected EOF or 0 bytes from the transport stream". I tried adding the ServerCertificateValidationCallback and returning true to ignore any issues with the server cert and setting the security protocol to ssl3 or tls. I made sure I downloaded the certificate from the site and installed it's root cert chains in the trusted root of the localMachine store location. I also installed the site's cert into the LocalMachine's personal and trusted people store. Yet, still I get this same error. I'm not sure what else to try at this point.

The following is my code to connect to the webservice:

 HttpWebRequest myReq =
                (HttpWebRequest)WebRequest.Create(Url);
            myReq.Method = "POST";
            ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3| SecurityProtocolType.Tls;

            byte [] lbPostBuffer = System.Text.Encoding.GetEncoding(1252).GetBytes(sb.ToString());
            myReq.ContentType = "text/xml; charset=utf-8";
            myReq.ContentLength = lbPostBuffer.Length;
            myReq.Accept = "text/xml";

            Stream loPostData = myReq.GetRequestStream();

Any help is appreciated. Thanks in advance!!

ptn77
  • 567
  • 3
  • 8
  • 23

2 Answers2

8

I found my answer. Looks like the webservice I was trying to connect to is using higher tls versions. I had to update my application to use .net framework 4.5 in order to do the following:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;
ptn77
  • 567
  • 3
  • 8
  • 23
  • You can add the patch for the framework 3.5, mentioned here https://stackoverflow.com/questions/43240611/net-framework-3-5-and-tls-1-2 – Juan Acosta Aug 21 '18 at 05:41
1

I working on this error too, it only happens on my Windows XP machine though. Have you tried it in Windows 7 or later?

  • I'm running mine on windows server 2008. I'll try other versions of windows to see if I get different results. Thanks! Please let me know if you find a solution to your issue. – ptn77 Mar 24 '17 at 13:46
  • I tried running my app on windows 7 with Chrome and still get the same error. When I was running my app on windows server 2008 R2, I was using internet explorer. I'm going to try to see if I can get my application to specify the use of Tls1.2 instead of sslV3 or Tls1. – ptn77 Mar 24 '17 at 15:40
  • I found my issue @user3755567. I had to update my application to use .net framework version 4.5 in order to specify higher tls versions: – ptn77 Mar 24 '17 at 19:13
  • Same as user3755567, I only get this error when running my code on Windows XP. Any higher version of Windows and the exact same code works fine. My code is compiled using .net framework 3.5 - I'll try recompiling under a newer version of .net and see if that solves the problem. – Joe Irby Aug 10 '18 at 21:32
  • Increasing to dotnet version 4.0 didn't stop the exception from happening on Windows XP. I didn't try version 4.5 because my XP test machine didn't have that framework installed. – Joe Irby Aug 13 '18 at 15:03