Is there some way to handle async/await behind an ASMX service?

It may be possible to do this, but it would be a bit awkward. ASMX supports APM-style asynchronous methods, and you can convert TAP to APM (however, note that the MSDN example on that page does not propagate exceptions correctly).

I have an example on my blog that shows how to wrap TAP implementations in APM (with exception propagation that keeps the correct exception type but loses the stack; see ExceptionDispatchInfo for fully correct exception propagation). I used this for a while when WCF only supported APM. A very similar approach should work for ASMX.

However, note that you will have to target 4.5 (i.e., httpRuntime.targetFramework) for async/await to work as expected.

Leave a Comment