Below highlighted is where code gets error. I include some other code as it may be useful. Not sure what is happening as the code worked before for many months and now all of a sudden it stopped working. It seems that it is not able to send the HTTP request. The windows service is running on a Windows 2003 server.
I tried running on a different proxy and without one on the server and still get the same error.
HttpWebRequest webRequestExAnte = CreateWebRequest(_url, _action);
using (WebResponse webResponse = webRequestExAnte.EndGetResponse(asyncResultExAnte))*****errors out saying underlying connection is closed: An unexpected error occurred on a send
using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
soapResultExAnte = rd.ReadToEnd();
private static HttpWebRequest CreateWebRequest(string url, string action)
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.ContentType = "text/xml";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
webRequest.ProtocolVersion = HttpVersion.Version11;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
ServicePointManager.DefaultConnectionLimit = 200;
//create the proxy
ICredentials credentials = new NetworkCredential("X Datafeed", "");
IWebProxy webProxy = new WebProxy(ConfigurationManager.AppSettings.Get("ProxyAddress") + ":" + ConfigurationManager.AppSettings.Get("ProxyPort"), true);
webProxy.Credentials = credentials;
webRequest.Proxy = webProxy;
//add the certificate
X509Certificate2 col = new X509Certificate2(ConfigurationManager.AppSettings.Get("Path"), ConfigurationManager.AppSettings.Get("XFeedPwd"), X509KeyStorageFlags.MachineKeySet);
catch (Exception ex)
EventLog eventlog = new EventLog();
eventlog.Source = "XFeed";
eventlog.Log = "XLog";
eventlog.WriteEntry("Exception encountered in CreateWebRequest: " + ex.Message.ToString(), EventLogEntryType.Warning);
//webRequest.KeepAlive = true; -- tried this here didn't work
It looks to be getting an error where the *** are above when I step through the code. Error message is: The underlying connection was closed: An unexpected error occurred on a send.
Any yes I looked at this article http://support.microsoft.com/kb/915599/en-us
but still could not resolve.