[英]How to better debug a WebService asmx — 500 Internal Server Error
I need the errors from my web service sent directly to the client in Json format so I can read exactly what error is being thrown.我需要将 web 服务中的错误以 Json 格式直接发送到客户端,这样我就可以准确地读取正在抛出的错误。 How do I do this please?请问我该怎么做?
This is what I keep getting in Fiddler这就是我在 Fiddler 中不断得到的
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed.
Details: To enable the details of this specific error message to be viewable on the local server machine, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "RemoteOnly". To enable the details to be viewable on remote machines, please set "mode" to "Off".
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="RemoteOnly"/>
</system.web>
</configuration>
Server code服务器代码
<WebMethod(EnableSession:=True)> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
Protected Function PopulateUsers() As IDictionary(Of String, String)
Dim users As New Dictionary(Of String, String)
Try
Dim arry As ArrayList = UserController.GetUsers(0, True)
For Each objUser As Users In arry
userrole.Add(CStr(objUser.UserID), objUser)
Next
Catch ex As Exception
Dim ur As New Dictionary(Of String, String)
Dim s As New User
s.DisplayName = ex.GetBaseException.StackTrace
s.UserID = 1
users.Add(ex.GetBaseException.Message, s)
Return s
End Try
Return users
End Function
Make sure you have proper error handling in your web service.确保在 web 服务中进行正确的错误处理。 In case of any error, convert your error object into a well formed json object and send it.如果出现任何错误,请将您的错误 object 转换为格式正确的 json object 并发送。 In the client side, success handler will only be invoked but you need to check whether the response contains the error object or the actual response and act accordingly.在客户端,只会调用成功处理程序,但您需要检查响应是否包含错误 object 或实际响应并采取相应措施。
There is error in your catch block, try this你的 catch 块中有错误,试试这个
Protected Function PopulateUsers() As IDictionary(Of String, String)
Dim users As New Dictionary(Of String, String)
Try
Dim arry As ArrayList = UserController.GetUsers(0, True)
For Each objUser As Users In arry
userrole.Add(CStr(objUser.UserID), objUser)
Next
Catch ex As Exception
Dim ur As New Dictionary(Of String, String)
ur.Add("ERROR", ex.GetBaseException.StackTrace)
Return ur
End Try
Return users
End Function
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.