在我的Form_Load background_worker_DoWork
内部启动,我正在使用wcf服务调用来获取countAllBooksValue。在服务中我正在抛出Fault异常,其中该异常应该被客户端捕获,但事实并非如此。
客户端
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
try
{
int countAllBooks = BookAgent.CountAllBooks();
e.Result = countAllBooks;
}
catch (FaultException ex)
{
MessageBox.Show(ex.Message);
}
}
服务方
public int CountAllBooks()
{
throw new FaultException("Something bad happened!");
}
问题是:为什么客户端没有捕获此FaultException?
答案 0 :(得分:1)
尝试设置IncludeExceptionDetailInFaults属性:
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]