Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to process long running requests with an HTTP handler under IIS?

I need to process long running requests inside IIS, handling the request itself is very lightweight but takes a lot of time mostly due to IO. Basically I need to query another server, which sometimes queries a third server. So I want to process as many requests as I can simultaneously. For that I need to process the requests asynchronously how do I do that correctly?

Using the Socket class I could easily write something like :

// ..listening code
// ..Accepting code

void CalledOnRecive(Request request)
{
    //process the request  a little
    Context context = new Context()
    context.Socket  = request.Socket;
    remoteServer.Begin_LongRunningDemonicMethod(request.someParameter, DoneCallBack, context);
}

void DoneCallBack( )
{
    IAsyncresult result = remoteServer.Begin_CallSomeVeryLongRunningDemonicMethod( request.someParameter, DoneCallBack, context);

    Socket socket = result.Context.Socket;
    socket.Send(result.Result);
}

In the example above the thread is released as soon as I call the "Begin..." method, and the response is sent on another thread, so you can easily achieve very high concurrency . How do you do the same in an HTTP handler inside IIS?

like image 844
AK_ Avatar asked Jan 03 '12 21:01

AK_


People also ask

What is the use of Httphandlers when to use this?

An HTTPhandler may be defined as an end point that is executed in response to a request and is used to handle specific requests based on extensions. The ASP.Net runtime engine selects the appropriate handler to serve an incoming request based on the file extension of the request URL.

How are Httphandlers gets configured?

To create a custom HTTP handler, you create a class that implements the IHttpHandler interface to create a synchronous handler. Alternatively, you can implement IHttpAsyncHandler to create an asynchronous handler. Both handler interfaces require that you implement the IsReusable property and the ProcessRequest method.

Which DLL file is used for processing ASP NET page request?

aspnet_isapi. dll initiates HttpRuntime. HttpRutime calls the ProcessRequest method in the page requested which starts processing of the request. During this time, it also creates and initializes core objects such as HttpContext, HttpRequest, and HttpResponse.

How request and response works in ASP net?

When the server receives an HTTP request, it processes that request and responds to the client. The response tells the client if the request was successful or not. ASP.NET Core is a web application framework that runs on the server.


1 Answers

You can implement an HttpHandler with IHttpAsyncHandler. MSDN has a nice walkthrough with examples on how to do that here.

like image 53
vcsjones Avatar answered Sep 30 '22 01:09

vcsjones