I am trying to call a WCF service using HttpWebRequest
. When I call it the first time, I get this error:
The underlying connection was closed: An unexpected error occurred on a send
If I call the same URL again, it is successful. Is there a reason why this call would cause an error the first time - and then it works?
This is my C# code to make the WCF call:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("<URL>");
request.Timeout = 200000;
request.Method = method;
request.UserAgent = "Foo";
request.Accept = "*/*";
request.MaximumAutomaticRedirections = 4;
request.KeepAlive = false;
request.AllowAutoRedirect = false;
request.ContentLength = 0;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
| SecurityProtocolType.Tls11
| SecurityProtocolType.Tls12
| SecurityProtocolType.Ssl3;
HttpWebResponse loWebResponse = (HttpWebResponse)request.GetResponse();