Windows services and System.Net.HttpWebRequest.GetResponse()

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Buenas,

Expondre mi problema a ver si pueden ayudarme.


1. Descripción del aplicativo: Tengo un servicio windows que consulta
de una URL información XML de un proveedor de datos(un feed), este
servicio procesa la información y la almacena en una BD local.


2. El método que utiliza el servicio Windows para consultar los datos
del URL es el siguiente:


public XmlDocument GetXMLHttp(string strURL)
{
//WebRequest request = WebRequest.Create(strURL);
HttpWebRequest request =
(HttpWebRequest)WebRequest.Create(strURL);;
request.Timeout = 10000; // 10 secs
request.Method = "POST";
XmlDocument rssDoc = new XmlDocument();
WebResponse response = null;
try
{
request.Credentials =
CredentialCache.DefaultCredentials;
if (request is HttpWebRequest)
{
((HttpWebRequest)request).UserAgent = ".NET
Framework Test Client";
}
// Get the response.


--------------------------------------------------------------------------------------------------------------------------------------
------------------------Inicio: linea donde se genera
el error --------------------------------------------------------
response = request.GetResponse();
------------------------Fin: linea donde se genera
el
error ---------------------------------------------------------


-------------------------------------------------------------------------------------------------------------------------------------
// Get the stream containing content returned by the
server.
Stream dataStream = response.GetResponseStream();
rssDoc.Load(dataStream);
// Clean up the streams and the response.
dataStream.Close();
response.Close();
request.KeepAlive = false;


}
catch
{
if (response != null)
response.Close();
request.KeepAlive = false;


WebProxy proxyObject = new WebProxy("192.168.0.2",
8080);
proxyObject.Credentials = new
NetworkCredential("Usuario", "clave", "xxxx");
proxyObject.BypassProxyOnLocal = true;
WebRequest.DefaultWebProxy = proxyObject;
request = (HttpWebRequest)WebRequest.Create(strURL);
//Obtener respuesta de la url que se invoca
try
{
response = request.GetResponse();
//Obtener datos de la url en un objeto Stream
Stream rssStream = response.GetResponseStream();
rssDoc.Load(rssStream);
rssStream.Close();
response.Close();
request.KeepAlive = false;


}
catch(WebException e)
{
if (response != null)
response.Close();
request.KeepAlive = false;


if
(Convert.ToBoolean(Dictionary(AppDomain.CurrentDomain.BaseDirectory.ToStrin-
g()
+ "\\XML\\Config.xml", "Log", "/Config/AppConfig")))
{
//enviar correo advirtiendo del error
System.IO.StreamWriter myFile = new
System.IO.StreamWriter("C:\\error\\errorLectura" +
DateTime.Now.ToString("MMddyyyy HHmmssfff") + ".txt");
myFile.WriteLine(e);
myFile.Close();
}
}
}
return rssDoc;
}


3. Bueno ahora el molesto problema: el servicio corre bien por un
tiempo, consulta los datos del URL y hace todo el resto del proceso
bien, pero al cabo de unas horas el sistema me reporta el siguiente
error del método anterior(punto 2):


System.Net.WebException: Unable to connect to the remote server --->
System.Net.Sockets.SocketException: A connection attempt failed
because the connected party did not properly respond after a period
of
time, or established connection failed because connected host has
failed to respond
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot,
SocketAddress socketAddress)
at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean
connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress&
address, ConnectSocketState state, IAsyncResult asyncResult, Int32
timeout, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetResponse()
at MarcadorCORE.MarcadorXMLUtils.GetXMLHttp(String strURL)


4. he intentado de todo como modificar el método de tal forma en que
si falla la consulta de la información por el proxy, este haga una
autenticación etc. agradeceria enermomente cualquier comentario que
me
ayude a solucionar el problema, o si tienen algun algoritmo que haga
este tipo de proceso y funcione bien, será bien recibido.


Muchas gracias.


.



Relevant Pages

  • Re: AJAX & XMLHttpRequests: Pushen von Daten von Servlets in Clients (Browser)
    ... XMLHttpRequest Ding eine Art "polling" macht und immer wieder diese URL ... mit welchem Browser was genau ... Mulitpart Messages als Response zurückgibt (diesmal mit dem Countdown ...
    (de.comp.lang.javascript)
  • Re: HTTP-Request und Responses
    ... > Ich habe bisher noch nie mit HTTP-Request und Responses gearbeitet. ... > Server senden und dann die Response erfrage. ... > Wie kriege ich das hin in VB, dass ich eine solche Request senden ... Das ist eigentlich nur eine URL, ...
    (microsoft.public.de.vb)
  • Re: W2K3 IIS 6.0 ASP.NET Requests Per Second Limits?
    ... allow the page to tell ASP.Net "don't send a response yet until I tell ... this request is "leaked" and will never ... It is when the callback executes with both the async function call ... The thread executing code literally calls into Function1, execute code, ...
    (microsoft.public.inetserver.iis)
  • Re: W2K3 IIS 6.0 ASP.NET Requests Per Second Limits?
    ... >> The way I understand async programming is if u need to do other ... >> request to webservice nothing more can be done until the result ... > The thread executing code literally calls into Function1, ... > the act of sending back the response using data that has been ...
    (microsoft.public.inetserver.iis)
  • ADFS & Sharepoint 2007 Errors
    ... Request or Response. ... claim Group = adfstest readers for user sid ... Sign In Response Dump ...
    (microsoft.public.windows.server.active_directory)