1

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?

Pop Catalin
  • 61,751
  • 23
  • 87
  • 115

1 Answers1

0

Do you use SilverlightFaultBehavior to decorate your service? If not, this may answer your question.

Dirk Brockhaus
  • 4,922
  • 3
  • 38
  • 47
  • What do you mean? SilverlightFaultBehavior in the link you provided is just the name of the custom class that derives from BehaviorExtensionElement and implements IEndpointBehavior that is created and registered to return an http status code 200 even when exceptions are thrown. The `System.ServiceModel.Web.WebOperationContext.Current.OutgoingResponse.StatusCode = Net.HttpStatusCode.OK` statement does the same thing. – lollercoaster May 10 '12 at 13:58
  • If you add a Silverlight-enabled WCF service to your ASP.NET host, the class SilverLightFaultBehavior is automatically integrated into your project and the new service is attributed with it. Strongly typed faults are working, as long as you remove this attribute. If you remove the attribute they stop working. I never questioned the implementation details of SilverlightFaultBehavior. – Dirk Brockhaus May 10 '12 at 14:46