5
Answers

System.Net.WebException: The request was aborted: The request was canceled. at System.Net.HttpWebRequest.GetResponse()

Ask a question
tanmayee sahoo

tanmayee sahoo

15y
14.2k
1
Hi,

I am developing a web service to integrate QuickBooks data with a CRM using C#.
CRM API exposes a method to get data from CRM.

I am calling the method to get the data from CRM inside back ground worker and doing some other stuff in the fore ground. Below is the code i have written to accomplish the task

public DataTable GetZohoAccountRecords(string zohoTicket)
{
          DataTable dtZohoAccount = new DataTable();
              
           string    apiKey = ConfigurationManager.AppSettings["ApiKey"].ToString();

          string     accountURL = ConfigurationManager.AppSettings["GetAccountURL"].ToString() + zohoTicket + "&apikey=" + apiKey;

                gWebRequest = (HttpWebRequest)GetWebRequest(new Uri(accountURL));
              
                gWebRequest.Method = "GET";

               
                //------For getting the Web Response---------
                gWebResponse = (HttpWebResponse)gWebRequest.GetResponse();
              
               Stream  responseStream = gWebResponse.GetResponseStream();
                Stream Reader streamReader = new StreamReader(responseStream);
                zohoResponse = streamReader.ReadToEnd();
}


protected override WebRequest GetWebRequest(Uri uri)
        {
            HttpWebRequest webRequest = null;
            try
            {               
              
                webRequest = (HttpWebRequest)base.GetWebRequest(uri);
                webRequest.KeepAlive = false;
                //webRequest.ProtocolVersion = HttpVersion.Version10;
            }
            catch (Exception ex)
            {
                gQbws.WriteToLogFile("Exception in overriding GetWebRequest\t" + ex.ToString());
            }
            return webRequest;
        }



I am getting System.Net.WebException: The request was aborted: The request was canceled.   at System.Net.HttpWebRequest.GetResponse() while trying to get records from CRM.

Can anyone please tell me why I am getting this exception and what do I do to fix this exception.

Any help would be highly appeciated.

thanks
tanmayee


Answers (5)
Next Recommended Forum