views:

38

answers:

2

We've got the following WCF Service Contracts:

[ServiceContract(Namespace = "http://example.com", Name = "Service1")]
public interface IService1
{      
  [OperationContract]
  [FaultContract(typeof(Fault1))]
  ValidateUserResult ValidateUser(
                       string username, 
                       string password);
}

[ServiceContract(Namespace = "http://example.com", Name = "Service1")]
public interface IService1Async
{      
    [OperationContract(AsyncPattern = true)]
    [FaultContract(typeof(Fault1))]
    IAsyncResult BeginValidateUser(
                       string username, 
                       string password, 
                       AsyncCallback callback, 
                       object userState);

    ValidateUserResult EndValidateUser(IAsyncResult asyncResult);
}

[DataContract(Namespace = "http://example.com")]
public class Fault1
{
}

We are calling the async version of ValidateUser in the client side and we are throwing a FaultException<Fault1> on the server, but all the client receives is the base FaultException.

What can be the reason the contractually-specified fault is not being received?

A: 

Can you show us the catch statements for your call? The contract and everything looks fine to me...

In which order do you check for faults?? You would have to check for FaultException<Fault1> before checking for FaultException or CommunicationException - any chance you might have that order mixed up somehow?

Does it work when you call the sync version of the method?

marc_s
+1  A: 

We found now why. We are generating the fault from a Service Behaviour using the ProvideFault method. There we use code similar to the example at IErrorHandler.ProvideFault in msdn

The only difference was that we weren't passing the right action on the Message.CreateMessage overload. We copied exactly what gets generated in the case that we manually throw the fault and voila.

My excuses for not giving that last detail :-)

Román