ali raza

ali raza

  • NA
  • 80
  • 0

Unable to call HttpWebResponse.GetResponse() method from web service

Aug 13 2011 5:36 AM

Hi all,

I am having issue in calling HttpWebResponse.GetResponse(). Actuall I have a web service from where I called HttpWebResponse.GetResponse() method if gave me following exception:

Unable to connect to the remote server Inner Excpetion 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 [IP Address]

however; when I tried from web application the code runs fine, even if I paste the generated URL in the browser it works fine... but when I use web service the code fails and exception occurs. following the code line no 02 is causing exception

 

 

 

01   HttpWebRequest request = WebRequest.Create([URL]) as HttpWebRequest;
           
02   using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
03   {
04                   // Get the response stream  
05                    StreamReader reader = new StreamReader(response.GetResponseStream());

06                   // Read the whole contents and return as a string  
07                    strMessage = reader.ReadToEnd();
08   }



any help in this regards would be heighly appreciated,

Thanks in advance 


Answers (1)