// SERVER SIDE! public class ExceptionWrapper { private static void WrapExceptionInfo(Exception ex, XmlDocument doc, XmlNode root, ref string Message) { Message += string.Format("\nException: {0}\n{1}", ex.Message, ex.StackTrace.ToString()); XmlNode details; details = doc.CreateNode(XmlNodeType.Element, "ExceptionClass", SoapException.DetailElementName.Namespace); details.InnerText = ex.GetType().AssemblyQualifiedName; root.AppendChild(details); foreach(PropertyInfo pi in ex.GetType().GetProperties()) { if (pi.CanRead) { try { details = doc.CreateNode(XmlNodeType.Element, pi.Name, SoapException.DetailElementName.Namespace); object pi_value = pi.GetValue(ex, null); if (pi_value != null) { details.InnerXml = AttributeReaderWriter.SerializeObjectToString(pi_value.GetType(), pi_value).Replace("", ""); } root.AppendChild(details); } catch {} } } if (ex.InnerException != null) { details = doc.CreateNode(XmlNodeType.Element, "InnerException", SoapException.DetailElementName.Namespace); WrapExceptionInfo(ex.InnerException, doc, details, ref Message); root.AppendChild(details); } } public static SoapException WrapException(Exception ex) { if (ex is SoapException) return (SoapException)ex; XmlDocument doc = new XmlDocument(); XmlNode node = doc.CreateNode(XmlNodeType.Element, SoapException.DetailElementName.Name, SoapException.DetailElementName.Namespace); string msg = string.Empty; WrapExceptionInfo(ex, doc, node, ref msg); string url = string.Empty; if (HttpContext.Current != null) url = HttpContext.Current.Request.Url.ToString(); return new SoapException("Error when processing web service: " + msg, SoapException.ClientFaultCode, url, node); } // Client Side ! try { MethodInfo mi = ServiceType.GetMethod(MethodName); result = mi.Invoke(Service, parameters); } catch(Exception ex) { throw CatchException(ex); } // Analisys of InnerException Logic protected Exception CatchException(Exception exeption) { Exception result = null; if (exeption is SoapException) { SoapException ex = (SoapException)exeption; result = CatchException(ex, ex.Detail); } else { if (exeption.InnerException != null) result = CatchException(exeption.InnerException); else result = exeption; } return result; } protected ServiceException PrepearServiceException(SoapException ex, XmlNode ExceptionInfo) { ServiceException eException = new ServiceException(); eException.MethodName = ex.TargetSite.Name; eException.ExceptionNode = ExceptionInfo; eException.Exception = ex; XmlNode exceptionClassNode = ExceptionInfo.SelectSingleNode("ExceptionClass"); if (exceptionClassNode != null) eException.ServerExceptionClass = exceptionClassNode.InnerText.Trim(); if (ExceptionInfo.SelectSingleNode("IsUserException") != null) { eException.IsUserException = true; eException.UserMessage = ExceptionInfo.SelectSingleNode("Message").SelectSingleNode("string").InnerText.Trim(); eException.ServerExceptionReason = ExceptionInfo.SelectSingleNode("ExceptionReason").InnerText.Trim(); } return eException; } protected bool CatchException(SoapException ex, XmlNode ExceptionInfo) { ArrayList exArgs = new ArrayList(); exArgs.Add(PrepearServiceException(ex, ExceptionInfo)); XmlNode inner = ExceptionInfo.SelectSingleNode("InnerException"); if (inner != null) { while (inner.FirstChild != null) { exArgs.Add(PrepearServiceException(ex, inner)); inner = inner.SelectSingleNode("InnerException"); } } // Now you have in ArrayList all nested exceptions from server. // Next is your homework to find the one which you need to show Your code is here... }