While working with web apps, you often need to go beyond Visual Studio debugger and see what’s actually being pushed through the wire. This post is a cumulative cheat sheet on how to set up network capturing for various protocols present in .net ecosystem:
REST, plain http
Entity Framework, plain SQL
WCF, regardless of protocol
WebServices, SOAP
REST, http
Suppose you’re using a poorly written client library for some REST service and it fails. You can use the following configuration snippet in your web/app.config to capture a lot of diagnostic info and maybe figure out a work-around:
System.Net Information: 0 : [13844] Current OS installation type is 'Client'.
System.Net Information: 0 : [13844] RAS supported: True
System.Net Information: 0 : [13844] Associating HttpWebRequest#16506093 with ServicePoint#7448163
System.Net Information: 0 : [13844] Associating Connection#51986349 with HttpWebRequest#16506093
System.Net Information: 0 : [13844] Connection#51986349 - Created connection from 10.XXX:8145 to 10.XXX:80.
System.Net Information: 0 : [13844] Associating HttpWebRequest#16506093 with ConnectStream#24590318
System.Net Information: 0 : [13844] HttpWebRequest#16506093 - Request: GET /api/v1/bXXX HTTP/1.1
...
System.Net Error: 0 : [13844] Exception in HttpWebRequest#16506093::GetResponse - The remote server returned an error: (401) Unauthorized..
Entity Framework
Most useful EF single liner ever:
WCF
Add the following configuration to start logging entire SOAP/whatever communication between endpoints (works for both client and server):
The result file will be large and not exactly human-readable, but there’s Microsoft Windows SDK tool, called SvcTraceViewer.exe which makes it much easier to read. If you have Visual Studio installed, you will probably find this tool in: