Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在webservice方法引发异常时获取错误消息。_C#_Javascript_Asp.net_Web Services_Error Handling - Fatal编程技术网

C# 如何在webservice方法引发异常时获取错误消息。

C# 如何在webservice方法引发异常时获取错误消息。,c#,javascript,asp.net,web-services,error-handling,C#,Javascript,Asp.net,Web Services,Error Handling,我使用WebServiceProxy.invoke调用webservice方法。我意识到其中一个参数是处理方法抛出异常时出现的错误的函数 我尝试方法get_message()获取错误消息。当我从localhost访问它时,它工作得很好。但当我从远程计算机访问该方法时,消息被一个标准错误更改:“处理请求时出错” ASP.net运行时错误不会在部署环境中显示给您的客户,您的服务器已正确配置为不在部署中显示,如果您要调试代码,您可以在web.config中将,或者将其设置为RemoteOnly,然后在

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

我尝试方法get_message()获取错误消息。当我从localhost访问它时,它工作得很好。但当我从远程计算机访问该方法时,消息被一个标准错误更改:“处理请求时出错”


ASP.net运行时错误不会在部署环境中显示给您的客户,您的服务器已正确配置为不在部署中显示,如果您要调试代码,您可以在
web.config
中将,或者将其设置为
RemoteOnly
,然后在服务器上调试代码

您使用的是哪种web服务(WCF、ASMX)?相关问题:,@AhmadFirdaus您在客户端使用的是什么库(如果有)?如果它是jQuery或ExtJS之类的标准配置,那么Ajax调用应该有一个类似
error
fail
的配置选项,可以用来处理返回的响应(带有错误代码和响应文本)。
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());
}