Debugging WCF can be hard. Frusteratingly hard. Small details can easily cause failures; A simple namespace mismatch on an XML envelope, for instance, will cause the entire message to be dropped silently by the server. Luckily, WCF with the .NET Framework comes with several logging and debugging tools that allow you, the developer, to hook directly into the messaging stack and get all the information you need. Unfortunately, the .NET Compact Framework does not have these hooks due to size constraints and prerequisites that are also not implemented. What is one to do?

You might have seen the .NET Compact Framework Power Toys CTP I blogged about earlier, and if you were thinking we might have something to help out included with that, then you would be absolutely correct. Here's a quick and dirty run-through on how to use our new remote logging tool for WCF. You can download these tools at this MSDN download link.

First off, deploy your favorite WCF project/sample to your device or emulator of choice and then run the .NETCF Logging Configuration.

Step 1: Connect the remote logger to your device

Step 1

This step is easy, simply select your device or emulator image from the device drop-down menu. The .NETCF Remote Logger will be deployed to the device and be ready to go.

Step 2: Enable network logging

Step 2

While you can select other things to log, we only really care about the network logging, so check the Network box.

Step 3: Run your program

Step 3

Run your program on your device and you should get the same dialog as shown above. Select yes to continue with the tracing. Now, go through your program and utilize WCF.

Step 4: Copy the log file to your desktop

Step 4

In the same directory as your program, assuming you left the log file directory text box blank, should be a the log file netcf_Network.log. Copy this to your desktop machine either by using a shared folder set up through the emulator configuration or browsing to it after connecting your device or emulator to your machine through ActiveSync or the Windows Mobile Device Center.

Step 5: Open the log file in the .NETCF Log Viewer

Step 5

From here you are able to see every single connection that was made and what information was sent over each of those connections. Shown for instance above is the sending of a simple Hello message wrapped in an XML envelope by one of our .NET Compact Framework WCF technology samples. More information can be shown, and additional columns can be added as needed to show virtually all of the status and data sent.

Step 6-?: Where to go from here

This is a powerful tool, and it can give you most of the information needed. There are a few problems with this approach though. This tool only will give you data sent and received by the device, so if you want the data sent and received from the server you're going to have to rely on the WCF logging solutions with the .NET Framework. Also, this approach is only effective when you can attach the .NETCF Remote Logger to the device. What about when the device is 'out in the field'?

As is usually the case, there are alternative solutions to this problem as well. When moving WCF From the .NET Framework to the .NET Compact Framework, it was made sure that the extensability that was so popular with WCF was maintained. It is therefore possible to make a logging binding element that can be inserted wherever is needed in the WCF messaging stack for both the .NET Framework and .NET Compact Framework. Alternatively, it is possible to simply modify the XmlSerializerWrapper used by many of the samples to wrap up the message and have it write out the XML to a file as well as the networking stream.

Please post comments if there is anything else you want me to run through with regards to the .NET Compact Framework and WCF.

-Dan