0
如果我对数据进行反序列化并在更新过程中稍后发生错误(例如:更改无法满足数据库约束)。我想在这里向最终用户报告一些有用的东西,但看起来.NET正在吞噬这个错误。任何想法为什么?ASP.NET Web服务返回400
<WebInvoke(method:="POST", uriTemplate:="changes", bodyStyle:=WebMessageBodyStyle.Bare)>
Public Function PostChanges(body As Stream) As String
Try
' This returns 500 Server Error (with wrapped exception)
'Throw New Exception("TEST")
Dim data As String = ""
Using reader As New StreamReader(body)
data = reader.ReadToEnd()
End Using
' This returns 400 Bad Request
'Throw New Exception("TEST")
' Code handling data removed (no error if exceptions are removed)
Catch ex As Exception
Throw New WebFaultException(Of DisplayError)(New DisplayError(ex.Message, ex.StackTrace), Net.HttpStatusCode.InternalServerError)
End Try
很可能你没有正确地调用你的web服务。调用代码在哪里? – Dalorzo 2014-12-02 15:51:53
另外,我强烈建议你使用'ex.ToString()'而不是ex.Message和ex.StackTrace。 – 2014-12-02 21:52:25