Search code examples
asp.netsslhttpwebrequest

Received an unexpected EOF or 0 bytes from the transport stream when getting request stream from ssl webservice


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!!


Solution

  • 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;