How to avoid ‘Not Found’ Error when making WCF Service Calls in Silverlight


Have you seen this error message before?  “The remote server returned an error: NotFound.”, Not particularly helpful! This is your Silverlight app’s way of telling you that there was an exception during a WCF Service call. 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.  The modification on the server can be made by defining a WCF endpoint behavior for Silverlight faults by implementing the following:

public class SilverlightFaultBehavior : BehaviorExtensionElement, IEndpointBehavior
{…}
The above WCF endpoint behavior needs to be configured for in the WCF web.config
<system.serviceModel>
    <extensions>
      <behaviorExtensions>
        <add name=”silverlightFaults” 
             type=”Microsoft.Silverlight.Samples.SilverlightFaultBehavior, 
             SilverlightFaultBehavior, 
             Version=1.0.0.0, 
             Culture=neutral, 
             PublicKeyToken=null”/>
      </behaviorExtensions>
    </extensions>
    <behaviors>
        <endpointBehaviors>
          <behavior name=”SilverlightFaultBehavior”>
            <silverlightFaults/>
          </behavior>
        </endpointBehaviors>
    </behaviors>
    <services>
        <service name=”Calculator.Web.Service”>
            <endpoint address=”” 
                      binding=”basicHttpBinding” 
                      contract=”Calculator.Web.Service” 
                      behaviorConfiguration=”SilverlightFaultBehavior” />
</service>
  </services>
</system.serviceModel> 

 

Here is a little sample application.

image

Click here to download the source code.

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

Advertisements

3 thoughts on “How to avoid ‘Not Found’ Error when making WCF Service Calls in Silverlight

  1. Victor, sorry but i am a bit baffled now…on several posts right here you trash talking steroids, and in this
    report you support and advocate a random modest chemical roid capsule.
    ..Why is that? So does that mea, no far more clear training for
    you?
    That’s unhappy trigger i truly discovered it truly good, that ultimately i felt like i identified a true non bullshit steroids web site 😦

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s