【发布时间】:2016-02-09 11:51:44
【问题描述】:
我有以下异步调用的方法。我想知道如何将System Exception(我可能在SQL 操作期间遇到)转换为FaultException。
方法如下:
public List<Product> GetProductDetails(int productKey)
{
try
{
using (SqlConnection con = new SqlConnection(_connectionString))
{
SqlCommand cmd = new SqlCommand("usp_Get_ProductDetails", con);
........
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
......
}
}
}
}
catch(Exception ex)
{
//How can I convert this Exception ex into FaultException and then throw to client?
//throw new FaultException(new FaultReason(new FaultReasonText()), new FaultCode());
}
}
【问题讨论】:
-
你能不能抓到
FaultException? -
stackoverflow.com/questions/17097839/… 为什么不从这里使用anwser?将异常类型传递给故障异常
-
@Steve 捕获然后抛出
FaultException的格式是什么?我想在客户端代码的 MessageBox 上显示FaultException.Reason。你能发布答案吗? -
@HumaAli 看到我的回答
标签: c# wcf exception-handling