Home > Mobile >  Limiting processing time of request for WCF or ASMX webservice
Limiting processing time of request for WCF or ASMX webservice

Time:01-09

Let say I have a webservice (WCF and ASMX .net framework 4.8) which is hosted on IIS 10. Webservice has a method with this content:

    public CustomerListResponse Get(CustomerListRequest request)
{
    //sleep for 1 hour
    System.Threading.Thread.Sleep(TimeSpan.FromHours(1));
    
    return new CustomerListResponse();
}

The line that is performing sleep on thread is just to show that there is code that in some cases can take long time.

What I'm looking is setting or way to limit allowed processing time for example to one minute and error returned to client. I want the processing be killed by IIS/WCF/ASMX if the execution time will exceed one minute.

Unfortunately I didn't found a way in IIS for that.

What I tried:

  • on binding for WCF there is couple of properties openTimeout="00:01:00" closeTimeout="00:01:00" sendTimeout="00:01:00" receiveTimeout="00:01:00" - I set them all but it didn't work. Code can still process for long time.
  • <httpRuntime targetFramework="4.8" executionTimeout="60" /> - also didn't work

I don't have other ideas how to achieve that, but I believe there should be some solution to be able control how long we want to spend on processing.

CodePudding user response:

You need to set the timeout on both client-side and server-side.

Client-side:

SendTimeout is used to initialize OperationTimeout, which manages the entire interaction of sending a message (including receiving a reply message in a request-reply case). This timeout also applies when a reply message is sent from the CallbackContract method. OpenTimeout and CloseTimeout are used to open and close channels (when no explicit timeout value is passed). ReceiveTimeout not used.

Server-side:

Send, open, and close timeouts are the same as on the client side (for callbacks). ReceiveTimeout is used by the ServiceFramework layer to initialize idle session timeouts.

CodePudding user response:

What if I don't have ability to control client side? I'm looking for hard rule for any request to limit it for 1 min (or any other timespan).

  • Related