While working on a project involving Silverlight and WCF REST I ran into some errors that didn’t give me much insight into the actual problem.

The error I got was:

System.Net.WebException: The remote server return an error: NotFound

The usual culprit is the message returning data greater than the default MaxMessageSize of 64K. In my case I was sure my message less than that.

I followed the following procedure to debug this error:

  1. Enable tracing in WCF through the web.config
    <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
    <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\log.svclog"></add>
  1. Run the application and trigger the error
  2. Open the log file (c:\log.svclog)
  3. Microsoft Service Trace Viewer will open up
  4. Navigate to the activity that caused the error
  5. See the stack trace

In my case the error was a DateTime issue. One of my date fields was not set and hence defaults to 0001-01-01 and hence couldn’t be serialized when it returns to the client.

In most cases if you get this type of error it usually is a serialization error.