简体   繁体   中英

How Set limit Send request per minute in BeginInvoke on sync c#

I have a bulk SMS Soap WebService From One of SMS provider, This web service has Limit 300 requests per minute, If I send more than 300 request, I get a limit error I don't know exactly how to handle requests at BeginInvoke so I don't send requests to the web service for more than 300 minute. How can I implement this restriction in my app by Threading – BeginInvoke? My app is written by C# Asp.net

This is Part of My code for send All request to Oprator Webservice:

endCache.SetCacheItem("Success", 0);
                    SendCache.SetCacheItem("Failed", 0);
                    SendCache.SetCacheItem("Invalid", 0);


                    object[] obj = new object[] { MessageID, msgParts, smsPrice, to,from, isUnicode, body };
                    IAsyncResult ar = sendIt.BeginInvoke(sender, to, body, isFlash,ref opCode, MessageID.ToString(), new AsyncCallback(SendCallback), obj);

                    SendCache.SetCacheItem("Result", ar);

private void SendCallback(IAsyncResult ar)
{
    string[] opCode = null;

    SendCache.SetCacheItem("Result", ar);


    AsyncResult aResult = (AsyncResult)ar;
    SendSmsDelegate sendIt = (SendSmsDelegate)aResult.AsyncDelegate;
    byte[] retVal = null;


        retVal = sendIt.EndInvoke(ref opCode, ar);
        SendCache.SetCacheItem("Retval", retVal);




    object[] obj = (object[])ar.AsyncState;

    ComputeReceptions((long)obj[0], (int)obj[1], (double)obj[2], (string[])obj[3], retVal, opCode, (long[])obj[4], (int)obj[5], (int)obj[6], (bool)obj[7]);


}

Thank you

There are 2 approaches, 1 is send only 5 sms in a second which is odd.Second one is use a queue .Put your sms that you want to send, in a queue and also keep what you sent by time. Then you can check if you do not pass the limit you pop from that queue and send it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM