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:
- Enable tracing in WCF through the web.config
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
<listeners>
<add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\log.svclog"></add>
</listeners>
</source>
</sources>
</system.diagnostics>
- Run the application and trigger the error
- Open the log file (c:\log.svclog)
- Microsoft Service Trace Viewer will open up
- Navigate to the activity that caused the error
- 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.