I am currently using several delegation handlers (classes derived from DelegatingHandler
) to work on the request before it is sent, for things like validating a signature etc. This is all very nice, because I don't have to duplicate signature validation on all calls (for example).
I would like to use the same principle on the response from the same web request. Is there something similar to the DelegatingHandler for the response? A way to catch the response before it has returned to the method, in a way?
Additional information:
I am calling a web api using HttpClient.PutAsync(...)
Here is an example for intercepting the request, and the response. the overridden method SendAsync is used to capture the original request, whereas the method called ResponseHandler is used to capture the response.
Example to capture original request and response
To use this method, the class needs to be identified and registered as a MessageHandler. I added the following line to my Global.asax file...
Example how to register the new MessageInterceptor class
Here is my complete Global.asax file. Notice how the MessageInterceptor is referenced...
Full version of Global.asax showing MessageInterceptor integration
Yes. You can do that in the continuation task.
I explain it here.
For example, this code (from the blog above) traces request URI and adds a dummy header to response.