user2783193
user2783193

Reputation: 1012

How to catch wcf service thrown exception at client side

Inside my Form_Load background_worker_DoWork is started where I'm using wcf service call to get countAllBooksValue. At service I'm throwing Fault exception where that exception should be catched by the client, but it doesn't.

client side

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                int countAllBooks = BookAgent.CountAllBooks();
                e.Result = countAllBooks;
            }
            catch (FaultException ex)
            {
                MessageBox.Show(ex.Message);                             
            }            
        }

service side

public int CountAllBooks()
{
   throw new FaultException("Something bad happened!");
}

Question is: Why this FaultException is not catched by the client?

Upvotes: 0

Views: 1667

Answers (1)

Alex
Alex

Reputation: 322

Try to set IncludeExceptionDetailInFaults property:

[ServiceBehavior(IncludeExceptionDetailInFaults = true)]

Upvotes: 1

Related Questions