I know you are all going to answer \"use a debugging proxy server like Fiddler\" but it\'s not that simple.
Here\'s my situation: I have some code that runs on a ser
I suggest you to download Telerik Fiddler to capture incoming/outcoming traffic.
Over here is simple example how to do it by that tool:
I know this is an old question, but I was in a tough spot where I didn't control the application config file, so I needed an easy way to enable the tracing via code and then easily access the raw request/response data in an event. So I put together this custom class, HttpRawTraceListener, which might be of use to others that are in my position:
https://github.com/jhilgeman/HttpRawTraceListener/blob/master/HttpRawTraceListener.cs
It was designed to be as simple as adding the file to your project, then calling:
System.Diagnostics.HttpRawTraceListener.Initialize();
...to start the trace. From there, requests/responses will be parsed out of the trace messages and then be made available via the System.Diagnostics.HttpRawTraceListener.FinishedCommunication event.
It's probably not 100% perfect for every scenario (e.g. it's not a proxy, so it won't capture web requests from a browser, for example), but it works pretty well for capturing HttpWebRequests requests/responses to web services, and it might be a good starting point if you need something like this.