Azure DevOps, Scrum, & .NET Software Leadership and Consulting Services

Free course! Predicting the Future, Estimating, and Running Your Projects with Flow Metrics

How to Permanently Banish Silverlight’s “Not Found” Error for WCF Service Calls

Have you seen this error message before?  “The remote server returned an error: NotFound.”  I think that this wins that the most infuriating exception in Silverlight.  I’ve personally wasted tens of hours trying to deal with this cryptic and utterly unhelpful message.  Over time, you come to understand that this is your Silverlight app’s way of telling you that there was an exception during a WCF Service call. 

Here’s the complete text of the exception:

System.ServiceModel.CommunicationException: The remote server returned an error: NotFound. —> System.Net.WebException: The remote server returned an error: NotFound. —> System.Net.WebException: The remote server returned an error: NotFound.
   at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
   at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState)
   at System.Net.Browser.AsyncHelper.<>c__DisplayClass2.<BeginOnUI>b__0(Object sendState)
   — End of inner exception stack trace —
   at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
   at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)
   — End of inner exception stack trace —
   at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
   at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result)
   at Benday.SilverlightFaults.TestService.TestServiceClient.TestServiceClientChannel.EndGetTime(IAsyncResult result)
   at Benday.SilverlightFaults.TestService.TestServiceClient.Benday.SilverlightFaults.TestService.TestService.EndGetTime(IAsyncResult result)
   at Benday.SilverlightFaults.TestService.TestServiceClient.OnEndGetTime(IAsyncResult result)
   at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)

Doesn’t tell you much, does it?

Well, it turns out that you don’t have to just live with this.  I had a discussion with Ramesh Seshadri at Microsoft last week and he said that you can fix this with a little WCF server-side magic.  The magic is described in the Silverlight documentation in an entry called Creating and Handling Faults in Silverlight

Here’s the condensed version of the answer.  It all comes down to making your WCF service return a 200 HTTP Status code instead of the default of 400 or 500. 

I did up a little sample application.  In the screen below, if you click the Throw Server Exception button, it calls a WCF service and the service will throw an exception. 


What’s great about this is that it plays nicely with the  includeExceptionDetailInFaults property of <serviceDebug />.  If the value for includeExceptionDetailInFault is set to true, you’ll get a descriptive error message (shown above). 


If the value is set to false, you’ll get an error message that is more friendly than “Not Found” but still shields the details of the WCF server exception from the client as shown below.


Click here to download the source code.



4 responses to “How to Permanently Banish Silverlight’s “Not Found” Error for WCF Service Calls”

  1. Benjamin Day Avatar

    My recommendation would be to create one or more non-Silverlight unit tests to exercise the WCF Service. Errors like what you’re talking about are probably just dev-time errors. A couple of quick unit tests would knock that out like a champ.


  2. Gilberto Tezini Avatar

    Excellent (and very Usefull) article Ben! Saved me also to find the real error detail in my WCF application.

  3. Gopala Avatar

    Set includeExceptionDetailInFaults to true only during development to troubleshoot a service.

  4. Gopala Avatar

    Set IncludeExceptionDetailInFaults to true only during development to troubleshoot a service.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.