Random “Not Found” error with Silverlight accessing ASP.NET Web Services

拜拜、爱过 提交于 2019-12-13 04:45:23

问题


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:


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.




回答2:


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!




回答3:


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.



来源:https://stackoverflow.com/questions/2548076/random-not-found-error-with-silverlight-accessing-asp-net-web-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!