views:

211

answers:

3

I'm developing an application with Silverlight 3 and ASP.NET Web Services, which uses Linq to SQL to get data from my SQL Server database.

Randomly when the user causes an action to get information from any of my web service methods, Silverlight throws the exception "The remote server returned an error: NotFound.", of type "CommunicationException", with the InnerException status of "System.Net.WebExceptionStatus.UnknownError".

Almost 10% of requests gets this error. If the user tries to get the same information again, normally the request has no errors and the user gets the data.

When debugging in Visual Studio only Silverlight stops on the exception, and I see no reason for the web service not being found.

+1  A: 

The problem you're seeing is because the web service does not return any details about the exception to the silverlight client whenever any exception occurs. It just returns a 404 not found status as the result and hence you always get the exception "Not Found".

What you can try and do is make sure your web service returns a 200(valid result) even in case of exception and somehow returns the error message along with the object.

example:

public class WebServiceResult

{

   //your object's properties go here


   //extra properties to check if exception has occured

   public string ErrorMessage {get; set;}

   public bool IsError {get; set;}
}

Use Fiddler to try and better understand what i'm saying. You'll see a 404 error in case of every exception.

Ritik Khatwani
A: 

As far as I know WebClient treats all errors as a "404". If you can switch the code to use HttpClient instead you will get more verbose errors. If that code is buried (or generated) then Fiddler will be your best bet.

infamouse
+1  A: 

if you happen to be using WCF web services, you might try turning on WCF Tracing in your web.config file:

<configuration>
   <system.diagnostics>
      <sources>
            <source name="System.ServiceModel"
                    switchValue="Information, ActivityTracing"
                    propagateActivity="true">
            <listeners>
               <add name="traceListener"
                   type="System.Diagnostics.XmlWriterTraceListener"
                   initializeData= "c:\CodePlex.Diagnostics\CodePlex.Diagnostics.Services.Web.svclog" />
            </listeners>
         </source>
      </sources>
   </system.diagnostics>
</configuration>

For context and details: READ ME!

Klay