简体   繁体   中英

Handling async ASMX web service exceptions

I've developed silverlight client with makes async web services calls to a asmx web service. The problem is, I want to handle exceptions, so far as to be able to tell in the client application whether there was an exception in the webservice (and therefore will be logged local to the webservice) or whether there was a communication problem (ie the endpoint for the webservice was wrong).

In testing both types of exceptions in my project I get the same generic exception:

System.ServiceModel.CommunicationException: The remote server returned an error: NotFound.

This exception is amazingly useless when an exception occured in the webservice as it clearly has been found.

Is the presence of this generic error to do with security (not being allowed to see true errors)? It can't be the fact that I don't have debug strings as I'm running on a dev PC.

Either way, my question is, what's the best way to handle async errors in a commercial silverlight application?

Any links or ideas are most welcome! :)

Thanks a lot!

Andy.

I was attempting to find the "correct" solution for this as well. It isn't a good idea to return the raw exceptions, so this is a simplified version of what I came up with:

   public class AjaxResponse
    {            
        public string Message { get; set; }
        public string FullError { get; set; }
        public AjaxResponse() { }
        public AjaxResponse(Exception e) 
        {
            Message = e.Message;
            FullError = e.ToString();
        }
    }
    public class AjaxResponse<T> : AjaxResponse
    {
        public T Response { get; set; }

        public AjaxResponse() { }
        public AjaxResponse(Exception e) : base(e) { }
        public AjaxResponse(T resp)
        {
            Response = resp;
        }           
    }

Usage:

        [WebMethod]
        public AjaxResponse<T> DoStuff(...)
        {
            try
            {
                T value = new T(...);
                return new AjaxResponse<T>(value);
            }
            catch (Exception ex)
            {
                return new AjaxResponse<T>(ex);
            }
        }

Yes, the generic error deals with security. The idea being that if an attacker does find a fault in the page etc. The person doesn't know what the cause of the error was.

Have you turned on remote debugging in the serviceDebug tag?

http://www.mostlydevelopers.com/mostlydevelopers/blog/post/2009/01/14/Debugging-Tips-ndash3b-The-remote-server-returned-an-error-NotFound.aspx

This should return a less general error.

I think you may actually be getting a 404 error here. If there were an exception in the service but includeDetailsInException were set to false, then you'd get a FaultException with nothing but the Exception.Message .

I think you need to go look on the machine the service is running on to see if there were any errors or warnings at around the time your client received the exception. In particular, if the service is running on .NET 2.0 or above, then the default configuration of ASP.NET Health Monitoring will log a warning message to the Application event log when an unhandled exception occurs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM