429 Error from WCF Rest API call using c#

  • Thread starter Thread starter Pradeep Kumar Mukherjee
  • Start date Start date
P

Pradeep Kumar Mukherjee

Guest
Hello Experts,

I have a c# windows application which runs in many machines for instance say 200 machines.

From that application sometimes a WCF Rest API is called for validating some records from the server and send back proper responses against the validated data. Note that this call is done manually from a button click event. The WCF API is also written by me only.

Below code is used to interact with the WCF service from the windows application


public static bool CheckForResponseFromServer()
{
try
{
using (var client = new WebClient())
using (client.OpenRead("http://<Server where the API is hosted>"))
{
return true;
}
}
catch
{
return false;
}
}

public static DataTable MyApiWebRequest(string ApiUrl)
{
DataTable dtValidatedResponse = new DataTable();
if(CheckForResponseFromServer())
{
try
{
HttpWebRequest httpRequest = WebRequest.Create(ApiUrl) as HttpWebRequest;
httpRequest.ContentType = "application/Xml; charset=utf-8";
var response = (HttpWebResponse)httpRequest.GetResponse();
using (var sr = new StreamReader(response.GetResponseStream()))
{
string strResponseText = sr.ReadToEnd();
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(strResponseText);
XmlReader xmlReader = new XmlNodeReader(xmlDoc);
DataSet dsValidatedResponse = new DataSet();
dsValidatedResponse.ReadXml(xmlReader);
dtValidatedResponse = dsValidatedResponse.Tables[0];
}
}
catch (Exception ex)
{
WriteToLogFile(ex.ToString(), "UtilityClass => MyApiWebRequest => " + ApiUrl);
}
}
return dtValidatedResponse;
}


All of a sudden few machines say 4 - 6 machines started to give 429 error response from the method CheckForResponseFromServer().

For testing purpose I commented this checking method and directly called the main method but from there also same 429 error comes. Suppose at the beginning of the day you can make 1 to 2 requests, but after that 429 error starts to appear.

But the other machines doesn't face such issue. For them whenever they call the API call it works like a charm.

This API call is not made randomly, say 10 - 12 times in a day max.

Can anyone put some light into this matter. I have searched a lot and couldn't find the exact thing. Every where its saying rate limit has been reached but that couldn't be the case.

I have hosted the same API in IIS in 4 different applications i.e. out of 200 stores 50 stores to 1 API to decrease the load. But still this issue persists for those 4 - 6 stores.

Some help will be much appreciated.


Thanks & Regards

Pradeep


Regards Pradeep(PKM)

Continue reading...
 
Back
Top