Fiddler 2 is a great tool to monitor the http activity on a computer, and an excellent debugging and teaching tool for WCF and ASMX.
It’s free and you can download the latest version from here.
What I like about it most, is that it can display SOAP messages - request and response as a DOM. You can really see what those contract attributes are doing : )
For my very simple Calculator.Add operation it displayed the following:
Nice, no?
The problem is, that it works best when monitoring traffic between your computer and another IP address. When the server and client are both on your laptop – as they are in my demos – you need to tweak it a bit to get it to work.
There are a number of tweaks on the net, but not all of them work in every case.
Here is a quick summary of the ones I tried. For all tweaks, leave the server as is and modify the address that the client uses in it’s end point.
- Replace “localhost” with “localhost.” (yes, add a dot).
This one worked on my XP machine, but Vista throws an exception. - Replace “localhost” with “127.0.0.1.”
Vista throws an exception.
These two worked for me with Vista Business, IIS 7.0 and with a WCF client and server (Visual Studio 2008).
- Replace “localhost” with “<name of your machine>”.
- Replace “localhost” with “ipv4.fiddler”.
For a WCF client use the following code (change “ipv4.fiddler” to test the other options).
CalculatorServiceClient proxy = new CalculatorServiceClient();
string uriAsString = proxy.Endpoint.Address.Uri.ToString();
string newUriString = uriAsString.Replace("localhost", "ipv4.fiddler");
proxy.Endpoint.Address = new EndpointAddress(newUriString);
result = proxy.Add(20, 11);
By the way, this works for ASMX Web Service clients too. Like so:
Service service = new Service();
service.Url = service.Url.Replace("localhost", "localhost.");
This worked for me on XP - I didnt try it on Vista. I assume that here also, the dot would throw an exception but that I could use the machine name successfully.
When using WSE with ASMX, you need to make an additional change - due to the SOAP headers associated with WS Addressing:
ServiceWse service = new ServiceWse();
string address = service.Url;
string addressVia = service.Url.Replace("localhost", "localhost.");
service.Destination = new EndpointReference
(
new Uri(address),
new Uri(addressVia)
);
Its a bit of a twiddle – but it’s worth checking which option works for you.
It’ll really open up the world of SOAP!