开发者

Limit number of web service calls within timeframe

开发者 https://www.devze.com 2023-02-25 11:11 出处:网络
I have an asmx web service which takes a few simple types as input, calls an oracle stored procedure from which it gets a response and then passes this response back to the caller.

I have an asmx web service which takes a few simple types as input, calls an oracle stored procedure from which it gets a response and then passes this response back to the caller.

I would like to take the inputs to the service and assuming that they are valid and the required operation is completed successfully, I'd like to store the inputs somehow (in an efficient way, so not hitting a database for example) for an agreed timespa开发者_开发知识库n, then refuse any attempts to call the service with the same data until after that timespan has expired. I hope that's clear.

So by way of pseudo code...

[WebMethod]
public Response DoThings(int someInt, string someString, DateTime someDateTime)
{
  if(!Stored(someInt, someString, someDateTime))
    {
       var response = new OracleRepository().CallStoredProcedure(someInt, someString, someDateTime);
       StoreInputs(someInt, someString, someDateTime);

       return response;
    }
  else return Response.TryLater;

}

private void StoreInputs(int someInt, string someString, DateTime, someDateTime)
  {
     Store(int someInt, string someString, DateTime, someDateTime);
  }

private bool Stored(int someInt, string someString, DateTime, someDateTime)
  {
     //some code to find out if the data is stored
  }

I'm not a complete beginner, but I am quite new to C#, so not quite sure where to start. Any help would be greatly appreciated.

Thanks.


using HttpContext.Current.Cache you should be able to cache the result of your stored procedure call and then on the next request query it for data and if found return that data instead of doing a new stored procedure call.

the .Add method on the cache class has parameters for data max age see: http://msdn.microsoft.com/en-us/library/system.web.caching.cache.add.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消