The deal with SendAsync and Send...

Topics: Web Api
Jun 21, 2011 at 12:31 PM
Edited Jun 21, 2011 at 12:41 PM

So let's say I have 3 channels (handlers?) with async tasks which all last respectively, say, 3, 4 and 5 seconds.

Do I understand it correctly that the method in my contract is 'hit' after 5 seconds? So, it waits till all async's are finished (since they can all alter the httpresponse) and then executes the method?

Am I also correct in assuming that if I past the same code to the Send override, it wil last 12 seconds before my contract method executes?

I guess my main question is; does it wait for all threads to end before the contract is hit? Otherwise, I can see the SendAsync being useful for logging, but not for security.

Thx again.

Jun 22, 2011 at 8:19 AM

Bump comment!

(truly sorry, but I need this answered, does anyone know?)

Jun 22, 2011 at 2:51 PM

Message handlers are asynchronously called one after the other in a "Russian doll" model. Each handler can either

a) Pass the request to the "inner" handler by calling SendAsync when it is done, or
b) Short-circuit the path by responding directly in which case the inner channel is not called

In your senario above, your service would get called after 3+4+5 = 12 secs but as the handlers are async you would not block any thead while waiting.

In fact the handlers must be async -- you can't override Send.


Jun 22, 2011 at 6:12 PM

Thx Henrik,

It's a little more clear. But then;

What advantage would the Delegating Channel have over, say, HttpModules (using aspnet compatibility)?

And, more importantly, Why can I not 'hook' into the pipeline with a completely asynchronous process? Logging is a prime example, I wouldn't want this to be part of the sequential code-path at all. 

With REST, we are moving to a model of our web application which no longer posts the entire page ( but does light-weight async http requests to the server, but it does do more of them! I want to interfere as little as possible with the pipeline.

Ideally, only security would be in there in our case.

Thx in advance for contemplating this with me.