0

I know a wcf method throws fault exception and client application catches that fault exception. But is there any way to know that whether that wcf method throws fault exception or not at client side ?

Shailesh Jaiswal
  • 3,606
  • 13
  • 73
  • 124

1 Answers1

0

When you create a WCF service you could decorate your operation contract with the [FaultContract] attribute:

[ServiceContract]
public interface IService1
{
    [OperationContract]
    [FaultContract(typeof(MyFaultContract))]
    void DoWork();
}

This emits information about this MyFaultContract in the metadata (WSDL) of the service. Then when you create a client proxy (either using the Add Service Reference in VS or directly by the svcutil.exe) this fault contract is known by the client and you can catch exceptions of this type.

So the idea here is to look whether your operation contract is decorated with the [FaultContract] attribute to know which type of fault contracts this operation might throw. If it hasn't any custom FaultContract attributes defined on it it means that on the client you can catch only for the non-generic version of the FaultException.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928