Thiago Sayão
Thiago Sayão

Reputation: 2367

WCF: can't catch FaultException(TDetail) - only non-generic FaultException

I am throwing FaultException<RetornoErro> on the server, but it's not being catched on the client. The client is only able to catch non-generic FaultException that does not expose the Detail.

Any ideas what might be missing or wrong?

My service contract:

[ServiceContract]
public interface IServicoLoja
{
    [OperationContract]
    [FaultContract(typeof(RetornoErro))]
    Retorno<Guid> AdicionarOuAlterar(Loja req);
}

implementation:

[ServiceBehavior]
public class ServicoLoja : IServicoLoja
{
    public Retorno<Guid> AdicionarOuAlterar(Modelo.Loja req)
    {
        try
        {
            ......
        }
        catch (Exception ex)
        {
            var ret = new RetornoErro(ex);
            throw new FaultException<RetornoErro>(ret, ex.Message);
        }
        .....
    }
}

service proxy:

public class ServicoLojaClient : ClientBase<IServicoLoja>, IServicoLoja
{
    public Retorno<Guid> AdicionarOuAlterar(Loja req)
    {
        return Channel.AdicionarOuAlterar(req);
    }
}

on the client:

try
{
    ...
}
catch (FaultException<RetornoErro> ex)
{
    //this is not reached
}
catch(FaultException ex)
{
    //this is reached
}

The service contract is on a separated assembly that is referenced on the client. The assembly that contains "RetornoErro" is also referenced.

Thanks.

Upvotes: 2

Views: 549

Answers (1)

Thiago Say&#227;o
Thiago Say&#227;o

Reputation: 2367

I have found the problem:

RetornoErro had a property with [DataMember] and no setter, so i guess it could not be unserialized.

Upvotes: 3

Related Questions