处理异步 ASMX Web 服务异常

发布于 2024-08-28 18:21:23 字数 501 浏览 3 评论 0原文

我开发了 silverlight 客户端,使异步 Web 服务调用 asmx Web 服务。问题是,我想处理异常,以便能够在客户端应用程序中判断 Web 服务中是否存在异常(因此将记录到 Web 服务本地)或者是否存在通信问题(即Web 服务的端点错误)。

在我的项目中测试这两种类型的异常时,我得到了相同的通用异常:

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

当 Web 服务中发生异常时,此异常毫无用处,因为它显然已经被发现。

此一般错误的存在是否与安全有关(不允许看到真正的错误)?我不可能没有调试字符串,因为我在开发 PC 上运行。

不管怎样,我的问题是,在商业 silverlight 应用程序中处理异步错误的最佳方法是什么?

非常欢迎任何链接或想法! :)

多谢!

安迪.

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 (i.e. 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

唱一曲作罢 2024-09-04 18:21:23

是的,一般错误涉及安全性。这个想法是,如果攻击者确实在页面等中发现了错误,那么该人不知道错误的原因是什么。

您是否在 serviceDebug 标签中打开了远程调试?

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

这应该返回一个不太常见的错误。

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.

乙白 2024-09-04 18:21:23

我认为您实际上可能会在这里收到 404 错误。如果服务中出现异常,但 includeDetailsInException 设置为 false,那么您将得到一个 FaultException,除了 Exception.Message 之外什么也没有。 。

我认为您需要查看运行服务的计算机,看看在您的客户端收到异常时是否有任何错误或警告。特别是,如果服务在 .NET 2.0 或更高版本上运行,则 ASP.NET 运行状况监控的默认配置将在发生未处理的异常时将警告消息记录到应用程序事件日志中。

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.

但可醉心 2024-09-04 18:21:23

我也试图为此找到“正确”的解决方案。返回原始异常并不是一个好主意,因此这是我想出的简化版本:

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

用法:

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

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);
            }
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文