在我的 WCF WebMethod 中,我有以下提供一些参数验证的代码。它工作正常并抛出 FaultException:
Public Function BeforeCall(operationName As String, inputs() As Object) As Object Implements IParameterInspector.BeforeCall
Dim u As MyAppUser = CType(inputs(0), MyAppUser)
If u.FirstName Is Nothing Then
Throw New FaultException(Of String)("First Name is Nothing", "First name must be a string value, and not empty.")
End If
Return u
End Function
然后,在消费应用程序中,我以触发错误的方式调用该方法(以检查它是否有效)。我捕捉到错误以提供反馈,如下所示:
Dim u As New ServiceReference1.MyAppUser
u.FirstName = Nothing
u.Surname = "SomeSurname"
Dim i As New ServiceReference1.Service1Client
Dim u2 As New ServiceReference1.MyAppUser
Try
u2 = i.GetDataUsingDataContract(u)
Catch fe As FaultException
Trace.Warn("FaultException Caught")
Trace.Warn(fe.Message)
Exit Sub
Catch ex As Exception
Throw
End Try
然而,在跟踪输出中,我只看到:
捕获的故障异常
名字必须是字符串值,并且不能为空。
谁能告诉我如何阅读 FaultException 详细信息以及抛出 FaultException 时提供的原因?
提前致谢。