OnAfterResponse system action for web service integration

OnAfterResponse system action for web service integration

  
I'm wanting to log my own web service calls for an integration, and I'm writing the web service error response in the OnAfterResponse system action.  The problem is that I don't have the request information in that scope to store with the log record.

How have any of you implemented something like this, where the web service response logging has all the pertinent request/response data that you need?

Thanks in advance!
great question!  'bump'
This would be helpful.

Solution
Hi all,

First of all I'm guessing that you are talking about Consume REST API's, right?
There is indeed no information during that callback with information to match with the request.
A easy way to do it is to create a small extension and store the request information in the Httpcontext.Current.Items object while in the OnBeforeRequest and read it on the OnAfterResponse calll.

BUt for the record, can you guys explain a bit more the requirement/reasons for custom logging. (since for throubleshooting use cases the platform already provides it out of the box) It will help us to improve the feature and make things like these easier in the future if they are really necessary.

Regards,
João Rosado
Solution
Hi Joao,
 
Thanks for the reply!  I've finally gotten around to now working on your proposed implementation since I've finalized the integration.
 
To answer your question about our use case: We are integrating with QuickBooks Online.  There are lots of different items/objects/resources that we sync with it.  In our syncing code we want to be able to log any errors that occur for each object that syncs so not only we (as developers) can track them and fix any syncing problems (programming error), but also for the future so our end-users can actually see relevant information in our application on a particular record that alerts them as to what they need to fix (user error).  When an object fails, we log an error, and continue on with the next object and try to sync it.
 
Hope that makes sense, and maybe you have any more thoughts on the subject.
 
Thanks again.
Joao,

I've never used HTTPContext Items and that's way easy and slick!  It works perfect for our use case of short term storage for a single HTTPRequest and retrieving that in the response when an error occurred in pushing a record to another system (QBO in our case).  Fantastic!  Thanks again