我使用 WebServiceProxy.invoke 来调用网络服务方法。我意识到其中一个参数是一个函数,用于处理方法抛出异常时出现的错误。
我尝试方法 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());
}
最佳答案
ASP.net 运行时错误不会在部署环境中显示给您的客户,您的服务器已正确配置为不显示 customErrors在部署中,如果你想调试代码,你可以设置 customErrors 的 mode
标志。在您的 web.config
中将其设置为 off
,或者将其保留为 RemoteOnly
并直接在服务器上调试代码!
关于c# - 当 web 服务方法抛出异常时如何获取错误消息。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8874743/