Random "Not Found" Error with Silverlight Accessing ASP.NET Web Services

I am developing an application with Silverlight 3 and ASP.NET Web Services that uses Linq to SQL to retrieve data from my SQL Server database.

In random order, when a user calls an action to retrieve information from any of my web service methods, Silverlight throws an exception "Remote server returned an error: NotFound.", Type "CommunicationException", with an InnerException state of "System.Net.WebExceptionStatus.UnknownError" .

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

When debugging in Visual Studio, only Silverlight stops with an exception, and I see no reason for the web service not to be found.

0
source share
3 answers

The problem you see is that the web service does not return any exception information to the silverlight client whenever an exception occurs. It simply returns 404 not found status as a result, and therefore you always get a “Not Found” exception.

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

Example:

public class WebServiceResult

{

   //your object properties go here


   //extra properties to check if exception has occured

   public string ErrorMessage {get; set;}

   public bool IsError {get; set;}
}

Fiddler, , . 404 .

+1

- WCF, WCF web.config:

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

: READ ME!

+1

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

0
source

Source: https://habr.com/ru/post/1732373/


All Articles