【问题标题】:How to get error message when a webservice method throw exception.当 web 服务方法抛出异常时如何获取错误消息。
【发布时间】:2012-02-11 01:59:57
【问题描述】:

我使用 WebServiceProxy.invoke 来调用一个 webservice 方法。我意识到其中一个参数是一个函数来处理当方法抛出异常时出现的错误。

我尝试方法 get_message() 来获取错误消息。当我从本地主机访问它时,这很有效。但是当我从远程计算机访问该方法时,消息被标准错误更改:“处理请求时出错”。

callws = function (args) {
    // call webservice to fill content panel
    Sys.Net.WebServiceProxy.invoke(_servicePath, _serviceMethod, false,
            { contextKey: args }, Function.createDelegate(this, onSubmitComplete),
              Function.createDelegate(this, onSubmitError), args);
    }

onSubmitComplete = function (result, userContext, methodName) {
    ...
}

onSubmitError = function (result, userContext, methodName) {
    // note: this result.get_message() contain exception message when
    // accessed from localhost, but contain "There was an error processing the request"
    // when accessed from remote computer
    alert(result.get_message());
}

【问题讨论】:

  • 您使用哪种网络服务(WCF、ASMX)?
  • @AhmadFirdaus 您在客户端使用什么库(如果有)?如果它是 jQuery 或 ExtJS 之类的标准,您的 Ajax 调用应该有一个配置选项,如 error 或 fail,您可以使用它来处理返回的响应(带有错误代码和响应文本)。

标签: c# javascript asp.net web-services error-handling


【解决方案1】:

ASP.net 运行时错误并不意味着在部署环境中显示给您的客户,您的服务器已正确配置为在部署中不显示customErrors,如果您想调试代码,您可以设置@将web.config 中的customErrors 的987654323@ 标志设置为off,或者将其保留为RemoteOnly 并直接在服务器上调试代码!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-17
    • 2012-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-19
    • 2017-01-23
    • 2012-03-06
    相关资源
    最近更新 更多