简体   繁体   English

如何在同步 c# 的 BeginInvoke 中设置每分钟发送请求的限制

[英]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.我有一个来自 SMS 提供商之一的批量 SMS Soap WebService,此 Web 服务每分钟限制 300 个请求,如果我发送超过 300 个请求,我会收到一个限制错误我不知道如何在 BeginInvoke 处处理请求,所以我不要向 Web 服务发送请求超过 300 分钟。 How can I implement this restriction in my app by Threading – BeginInvoke?如何通过 Threading – BeginInvoke 在我的应用程序中实现此限制? My app is written by C# Asp.net我的应用程序是由 C# Asp.net 编写的

This is Part of My code for send All request to Oprator Webservice:这是我将所有请求发送到 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.有两种方法,一种是在一秒钟内只发送 5 条短信,这很奇怪。第二种是使用队列。把你想发送的短信放在队列中,并按时间保留你发送的内容。 Then you can check if you do not pass the limit you pop from that queue and send it.然后你可以检查你是否没有超过你从该队列中弹出的限制并发送它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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