我遇到了WebServises异常处理问题。 当webservice抛出异常时,它会在catch(异常e)块
中执行但它将异常类转发给WsAppExcepotion,并在Detail.ErrorString中插入有关错误的信息
但是在课堂例外中,没有像细节这样的道具 所以我不能jest返回e.Detail.ErrorString
我试图像这样创建我的ownexception
public class WsException : Exception
{
public WsDetail Detail { get; set; }
public class WsDetail
{
public string ErrorMessage { get; set; }
public string InnerExceptionMessage { get; set; }
public string Source { get; set; }
public string StackTrace { get; set; }
public string Target { get; set; }
}
}
但它只是停止捕捉异常
catch (WsExseption e)
我也试过这个
public static void LogMeaningfulMessage(Exception e, string serviceName, string state)
{
var ed = e as FaultException<dynamic>;
if (ed != null)
{
Log.Error("Call to {0} for {1}, error: {2}", serviceName, state, ed.Detail.errorString);
}
else
{
if (e.InnerException != null)
{
LogMeaningfulMessage(e.InnerException, serviceName, state);
}
else
{
Log.Error("Call to {0} for {1}, error: {2}", serviceName, state, e.Message);
}
}
}
但是像varEx = e一样,出现了FaultException ed将为null ...
也许我做错了? 还是有其他方法从Detail获取此ErrorString?
我还尝试在Json中将其序列化并返回模型WsException ..对我来说不起作用......