我正在尝试将强类型的FaultExceptions从WCF服务传递到Silverlight客户端,但我得到的只是通用"远程服务器返回错误:NotFound。"响应,同时使用相同的代码来抛出通用的FaultExceptions可以正常工作。
因此,如果我执行Throw New FaultException()
,我会将其恢复到Silverlight回调的e.Error
参数中,而Throw New FaultException(Of clsServiceFault)(clsServiceFaultInstance)
会导致找不到错误。
clsServiceFault
已被声明为数据合同,如下所示:
<DataContract()> _
Public Enum ServiceFaultTypes
LoginFailed
SessionExpired
End Enum
<DataContract()> _
Public Class clsServiceFault
Public Sub New()
End Sub
Public Sub New(iType As ServiceFaultTypes, iMessage As String)
Type = iType
Message = iMessage
End Sub
<DataMember()> _
Public Property Type As ServiceFaultTypes
<DataMember()> _
Public Property Message As String
End Class
抛出错误的WCF方法已使用FaultContract
属性进行修饰,并且我还将HTTP响应状态代码更改为200.
<OperationContract()> _
<FaultContract(GetType(clsServiceFault))> _
Public Function GetCustomersData(...)
...
System.ServiceModel.Web.WebOperationContext.Current.OutgoingResponse.StatusCode = Net.HttpStatusCode.OK
Throw New FaultException() 'Works
Throw New FaultException(Of clsServiceFault)(new clsServiceFault(..)) 'Does not work
...
End Function
我在这里缺少什么?