WCF RIA Services - “Not Found” Error Message

The dreaded “The remote server returned an error: NotFound” error message in RIA Services can be frustrating if you are not aware of what it really means, and more importantly how to diagnose it.

This generic error message is due to network stack limitation in your browser, basically the browser is intercepting the error and not giving it all to Silverlight.  That does not mean there isn’t good information to be found.  Your friend here is Fiddler and/or WCF Service Tracing. 

NotFound vs OnError:  A NotFound generally means that something in the WCF side blew up, OnError will handle errors in your model (or custom code in your DomainService).  So when you see NotFound, overriding OnError will not be much help, break points placed inside of it will most likely not be reached during debugging, but its an easy place to start.

The first tool we are going to us is Fiddler, a web debugging proxy with a WCF Binary Inspector. This will show you all the requests are being made and will show you what error code, and possibly what error is being returned by your service. (Using Fiddler with ASP.Net Development Server / Casini)

Fiddler

If there is no good information in Fiddler then the next step is to hit your service url, which you can find in Fiddler.   In the picture above you can see that my service is at /ClientBin/HockeyStatsService-Web-HockeyStatsDomainService.svc (ProjectName-Web-DomainServiceName.svc).  Remember that RIA Services does not actually generate a .svc file for you, it is handled dynamically by the DomainServiceHttpModule, so don’t go looking for a physical file.

Actual 404:  If you hit your service in the browser and you still get a 404, then something is wrong with your deployment. 

Actual404

Check out Saurabh Pant’s Blog or Tim Heuer for good articles on deploying WCF Ria Services to IIS.

If you are using Casini (ASP.NET development server) then make sure your web.config is correct (Has proper references to DomainServiceHttpModule), and that you have a reference in your ASP.NET project to your service library (if you are using RIA Class Libraries, otherwise you should be fine on this point).

Now if you can hit your service url without a 404, but still get a NotFound, and the Fiddler response tab didn’t give you anymore insight we will move on to some other steps.

SvcTraceViewer: Visual Studio has a tool to help you configure WCF, it can be found under TOOLS | WCF Service Configuration Editor.  Use this tool to open your Web.Config and then on the ‘Diagnostics’ folder, turn on Message Logging and Tracing.  On the ‘Message Logging’ node, LogMessagesAtServiceLevel=true and LogMessagesAtTransportLevel=false.

WCFtraceConfig2

You can view the generated svclog files with C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\SvcTraceViewer.exe

In my example DomainService I am loading a large amount of hockey stats data.  When I open my svclog file and find the error generated I can see that the actual exception being thrown by my service says:

'Maximum number of items that can be serialized or deserialized in an object graph is '65536'. Change the object graph or increase the MaxItemsInObjectGraph quota. '.

WCFTraceViewer

Your message obviously might be different, but with that information you should be able to find a solution or at least provide the right information to the WCF RIA Services Forums so they can help find a solution

Another good debugging tip is to turn off custom errors in your Web.Config.  <customErrors mode="Off"/>  This will provide more informative exceptions to silverlight, however it also exposes information to the user that you may not intend, so do not leave this set to ‘off’ on a publicly available site.

If your error is the same as mine, take a look at Fixing the MaxItemsInObjectGraph.