Hyperbolic title aside, I have to share with you a tool that has proved invaluable not only for debugging Restful Http applications, but SOAP and anything else that uses Http.

TCPMon

TCPMon is a network monitoring tool that intercepts network traffic (http GETS and POSTS) before forwarding it on to its original destination.

It’s invaluable for debugging Http Rest or SOAP applications because it actually shows you all the traffic, headers, and post information flying between end points in your application.

How does it work?

Say we wanted to test the service we described in our last post which is configured to spin up a WCF end point listening on port 1980.

          <baseAddresses>
            <add baseAddress="http://localhost:1980" />
          </baseAddresses>

Connected to by a proxy that looked something like this:

            private IFooService CreateProxy()
            {
                EndpointAddress ep = new EndpointAddress("http://localhost:1980/abc");
		  ...	
		  
                return factory.CreateChannel();
            }

Instead of connecting directly to the endpoint directly:

you temporarily change your client proxy to point to the port TCPMon will be listening on (say 9090) and then have TCPMon forward that request off to port 1981 and return the corresponding response.

So our proxy client connection would look like this:

            private IFooService CreateProxy()
            {
                EndpointAddress ep = new EndpointAddress("http://localhost:9090/abc");
		  // TCPMon  listening here. Will forward to port 1980
		  ...	
		  
                return factory.CreateChannel();
            }

Setting up TCPMon to do this is dead easy. You just specify the port you want to listen on, and then the port you want to forward to. Click ‘Add’ and you are done.

Now when you run your tests you should now see something like this:

Beauty.

This tool has been invaluable for our team. It’s helps us create requests for automated integration tests, debug, and deal with a host of other issues that come up when building distributed applications.

It is written in Java, so if you don’t already have a Java JIT on your desktop you’ll need to install that first (download here).

Big thank you to Jonas Claesson for showing me this tool.

Good luck. And happy debugging!