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
Loading

Master BillaRank #2,229 · 630 reputationPosted Aug 12, 2009, 1:08 AM EDT
there first and most reason is your key(token not valid) to access the CRM.
2. Please check the url is correct after concatenate key
string accountURL = ConfigurationManager.AppSettings["GetAccountURL"].ToString() + zohoTicket + "&apikey=" + apiKey;
i think may be one & sign is missing before the the zohoTicket.(i think )
3.Please ping to normal to that server is working.
if those are OK fine then it will work
Note:Please verify you are composing acceptablt format to get the response from the CRM
Thank you
Roei BarRank #1,271 · 1.4K reputationPosted Aug 12, 2009, 1:59 AM EDT
here is a sample code with an Option To pass Credentials
public XmlDocument getResponseFromHTTP(string _CLI) { Stream reqStm = null; HttpWebRequest wreq = null; Stream resStm; StreamReader sr; HttpWebResponse wres; XmlDocument xmlRequset = new XmlDocument(); try { System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; string _ResponseXML = string.Empty; string txtRequest = string.Empty; wreq = WebRequest.Create(ConfigurationAssist.GetValue("LogNet")) as HttpWebRequest; if (ConfigurationAssist.GetValue("IgnoreCertificateErrors") == "1") ServicePointManager.ServerCertificateValidationCallback += AcceptAllCertificatePolicy; byte[] bytes = Encoding.ASCII.GetBytes(txtRequest); if (wreq != null) wreq.Method = "POST"; wreq.Credentials = CredentialCache.DefaultCredentials; wreq.Headers.Add("cli", _CLI); if (wreq != null) wreq.ContentLength = bytes.Length; if (wreq != null) reqStm = wreq.GetRequestStream(); if (reqStm != null) reqStm.Write(bytes, 0, bytes.Length); if (wreq != null) { wres = wreq.GetResponse() as HttpWebResponse; if (wres != null) { resStm = wres.GetResponseStream(); sr = new StreamReader(resStm); _ResponseXML = sr.ReadToEnd(); wres.Close(); sr.Close(); resStm.Dispose(); } wres.Close(); } xmlRequset.LoadXml(_ResponseXML); reqStm.Dispose(); return xmlRequset; } catch (WebException Webex) { //wres.Close(); //sr.Close(); //resStm.Dispose(); //wres.Close(); reqStm.Dispose(); return xmlRequset; } catch (Exception ex) { //wres.Close(); //sr.Close(); //resStm.Dispose(); //wres.Close(); reqStm.Dispose(); return xmlRequset; } }Master BillaRank #2,229 · 630 reputationPosted Aug 12, 2009, 2:14 AM EDT
yes, but he sending Key and token , so when you are access the CRM we don't need set
wreq.Credentials = CredentialCache.DefaultCredentials; most of the CRM support to public and private key encryption authentication. So we need send correct key which given by CRM when he loin to CR using user name and password. Thank youtanmayee sahoo3 reputationPosted Aug 12, 2009, 3:42 AM EDT
So I do n't think that it is because of url I am getting WebException. Can you please tell me what else could be the reason.
thanks
tanmayee
Master BillaRank #2,229 · 630 reputationPosted Aug 12, 2009, 9:05 AM EDT
I have a quick question , how do you get the token to attached with your url?
is it given by the CRM when you a re login to CRM using username and password.
could you give then quick book CRM url, i will work for you and give the code.
thank you