Nacho
Nacho

Reputation: 1013

WPF client does not catch custom exception from WCF

I have a custom exception and this works fine when the client is console application or forms application, but if the client is WPF not works. look but still I found no answer, any idea?

My basic custom error code:

[DataContract]   
public class BookingException
{
    [DataMember]
    public string Messsage { get; set; }
    [DataMember]
    public string Description { get; set; }
}

service interface code:

[OperationContract]
[FaultContract(typeof(BookingException))]  
void InsertBooking(Booking booking);

service code:

public void InsertBooking(Booking booking)
{
    throw new FaultException<BookingException>(new BookingException());  
}

Client code:

 catch (FaultException<BookingException> ex)
 {
       //TODO
 }
 catch (Exception ex)
 {
       //TODO
 }

This works fine when the client is a console application or forms application, but if this client code I put in WPF application, always the catch is the Exception, not the custom exceptions.

Upvotes: 2

Views: 151

Answers (1)

Nacho
Nacho

Reputation: 1013

I solved my problem with the comments helps. I have two proxys, one in my console application and other in my WPF applications, boths proxys use the same service reference, but both proxys have the diferente way the reference the service, this diference was the problem. WPF not have any problems with custom erros. Thanks to those who helped me with their comments.

Upvotes: 1

Related Questions