Iām trying to pass strongly typed FaultExceptions from a WCF service to a Silverlight client but all I'm getting is the generic "The remote server returned an error: NotFound." response, while using the same code to throw generic FaultExceptions works fine.
So, if I doThrow New FaultException()
I get it back in the e.Error
parameter of the Silverlight callback, while a Throw New FaultException(Of clsServiceFault)(clsServiceFaultInstance)
results in the not found error.
clsServiceFault
has already been declared as a data contract like so:
<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
The WCF method in which the fault is thrown has been decorated with the FaultContract
attribute and I'm also changing the HTTP response status code to 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
What am I missing here?