0
I’m having a problem when it comes to using the HttpWebRequest
, the first time I call the method to effect sending an NF-e to Sefaz’s Webservices it performs normally but the second time I try to send another NF-e it generates me the following error:
Request cancelled: Failed to create a secure channel for SSL/TLS.
More if I restart the WCF it performs the upload correctly.
Below is the code I’m using.
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
string XMLRetorno = string.Empty;
Uri uri = new Uri(url);
WebRequest webRequest = WebRequest.Create(uri);
HttpWebRequest httpWR = (HttpWebRequest)webRequest;
httpWR.Headers.Add("SOAPAction", metodo);
httpWR.ContentType = "application/soap+xml;charset=\"utf-8\"";
httpWR.Accept = "aplication/xml";
httpWR.Method = "POST";
httpWR.Timeout = Timeout.Infinite;
httpWR.KeepAlive = true;
httpWR.UseDefaultCredentials = true;
httpWR.Proxy = webProxy;
httpWR.ContentLength = Encoding.UTF8.GetBytes(xmlSoap).Length;
httpWR.ClientCertificates.Clear();
httpWR.ClientCertificates.Add(certificado);
Stream reqStream = httpWR.GetRequestStream();
reqStream.Write(Encoding.UTF8.GetBytes(xmlSoap), 0, Encoding.UTF8.GetBytes(xmlSoap).Length);
reqStream.Close();
reqStream.Dispose();
WebResponse webResponse = httpWR.GetResponse();
Stream respStream = webResponse.GetResponseStream();
StreamReader streamReader = new StreamReader(respStream);
XMLRetorno = streamReader.ReadToEnd();
streamReader.Close();
streamReader.Dispose();
return XMLRetorno;
I’m not sure, but it might be that you’re keeping the connection open even after sending, try changing this flag
httpWR.KeepAlive
he’s liketrue
placefalse
and take a test.– Lodi
@Lodi I put more now he’s giving all the time.
– Dionatas Firmino Machado