0
votes

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.

3
I'd suggest you try to characterize the requests that cause the error. Perhaps watch the network traffic with Fiddler or the like.John Saunders
I have seen this before when the web service client object gets re-instantiated (via a control reload or whatever); it may have been a coincidence in my application, but after refactoring to make sure this condition didn't occur, this seemed to solve the problem.Brandon

3 Answers

1
votes

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.

1
votes

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!

0
votes

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.