— New online course!  Getting Started with Azure DevOps — Special launch price 50% off —

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

by

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. 

image

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). 

image

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.

image

Click here to download the source code.

-Ben


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

Leave a Reply

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

%d bloggers like this: