Thanks Henning. Can I see WrapException and the client side unwrap
method(s)? TIA
Hello,
here we go:
============================================================================
WebserviceInvokationErrorException.cs:
============================================================================
public class WebServiceInvokationException: Exception, IEnumerable
{
private NameValueCollection _Details;
private string _Type;
private string _Message;
public string this[string name] { get { return _Details[name]; } }
public string this[int index] {get { return _Details[index]; } }
public string Type { get { return _Type; } }
private WebServiceInvokationException(): base() {}
private WebServiceInvokationException(string message, Exception
innerException): base(message, innerException) {}
public static WebServiceInvokationException UnWrap(SoapException
innerException)
{
NameValueCollection details = new NameValueCollection();
string type;
string message;
WebServiceInvokationException exception;
if (innerException == null) throw new ArgumentException("innerException
must not be null", "innerException");
if (innerException.Detail == null) throw new ArgumentException("Soap
exception does not contain any usable information", "innerException");
message = "";
type = "";
foreach (XmlElement node in innerException.Detail.ChildNodes)
{
if (string.Compare(node.LocalName, "Type", true) == 0) type =
node.InnerText;
else if (string.Compare(node.LocalName, "Message", true) == 0) message =
node.InnerText;
else details.Add(node.LocalName, node.InnerText);
}
exception = new WebServiceInvokationException(message, innerException);
exception._Details = details;
exception._Type = type;
return exception;
}
#region IEnumerable Members
public IEnumerator GetEnumerator()
{
return _Details.GetEnumerator();
}
#endregion
============================================================================
ServiceBase.cs
============================================================================
using System;
using Microsoft.Web.Services2;
using Microsoft.Web.Services2.Messaging;
using System.Web.Services.Protocols;
using System.Xml;
using System.Reflection;
using NAW.NoSpamProxy.WebServices;
namespace NAW.NoSpamProxy.WebServices.Implementation
{
/// <summary>
/// Summary description for ServiceBase.
/// </summary>
public abstract class ServiceBase: SoapService
{
private void AddInfo(XmlElement parent, string name, string info)
{
XmlElement node;
node = parent.OwnerDocument.CreateElement(name);
node.AppendChild(parent.OwnerDocument.CreateTextNode(info));
parent.AppendChild(node);
}
public XmlElement WrapException(Exception ex)
{
XmlDocument doc;
XmlElement node;
object value;
doc = new XmlDocument();
// Build the detail element of the SOAP fault.
node = (XmlElement)
doc.CreateElement(SoapException.DetailElementName.Name,
SoapException.DetailElementName.Namespace);
AddInfo(node, "Type", ex.GetType().FullName);
foreach (PropertyInfo info in
ex.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
{
try
{
value = info.GetValue(ex, null).ToString();
AddInfo(node, info.Name, (value != null) ? value.ToString() : "");
}
catch
{
AddInfo(node, info.Name, "");
}
}
return node;
}
protected override void Receive(SoapEnvelope envelope)
{
try
{
base.Receive(envelope);
}
catch (Exception ex)
{
throw new SoapException(ex.Message, SoapException.ClientFaultCode, "",
WrapException(ex.InnerException));
}
}
}
}
============================================================================
Each webservice call from the client is wrapped like this:
============================================================================
try
{
return (ProxyConfiguration)base.SendRequestResponse("MyMethod", new
SoapEnvelope()).GetBodyObject( typeof(MyMethodResponse));
}
catch (SoapException ex)
{
throw WebServiceInvokationException.UnWrap(ex);
}
Greetings,
Henning Krause
==========================
Visit my website: http://www.infinitec.de
Try my free Exchange Explorer: Mistaya
(http://www.infinitec.de/?page=products)
> Thanks Henning. Can I see WrapException and the client side unwrap
> method(s)? TIA
[quoted text clipped - 65 lines]
> > > > Here is the declaration of my Exception:
> > > > [Serializable]
[XmlRoot(Namespace=http://nospamproxy.netatwork.de/WebServices/ProxyConfigur
> > > > ation/ConfigurationException)]
> > > > public class CustomException: Exception
[quoted text clipped - 25 lines]
> > > > Try my free Exchange Explorer: Mistaya
> > > > (http://www.infinitec.de/?page=products)