I am trying to throw an exception from WCF module to the client module. I am getting the following error "FaultException was unhandled by the user"
at the service side
public IList<UserEntity> SearchUserDetail(string userName)
{
    try
    {
        int y = 0;
        int u = 9 / y;
        return new UserViewModel().SearchUserDetail(userName);
    }
    catch (Exception ex)
    {
        throw new FaultException(
        new FaultReason(ex.Message),new FaultCode("Data Access Error"));
    }                 
}
at the client side
try
{             
    ServiceReference.ServiceClient servRef = new ServiceReference.ServiceClient();
    List<UserEntity> users = new List<UserEntity>();
    users.AddRange(servRef.SearchUserDetail("Jacson"));
    dataGridView1.DataSource = users;            
}
catch (System.ServiceModel.FaultException  exc)
{
    Logging.Log(new Exception("Search User", exc));
}
In the app.config of the Service module I have added the following attribute
 serviceDebug includeExceptionDetailInFaults="True" 
Anyone know a solution?
You have to add the FaultContractAttribute to the method SearchUserDetail, if it has the OperationContractAttribute and is part of your ServiceContract class.
[ServiceContract]
interface IMyServiceContract
{
  [OperationContract]
  [FaultContract(typeof(...)]
  IList<UserEntity> SearchUserDetail(string userName)
}
I'm not sure about the type of the FaultContract. But have a look at msdn.
Shameless plug:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With