[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Mark Pearce

7/14/2003 9:15:00 PM

Hi Chris,

You don't need to serialize the Web service SoapException yourself - it's
done for you. All you need to do is to catch the original exception within
the method where it's thrown, and then create your own custom SoapException
with the details you want. Finally, just throw your custom SoapException,
and it should be caught within your client code.

The code at the end of this post shows a procedure that build a custom
SoapException based on the original SoapException. The key to understanding
this code is that every SoapException can have a Detail XML node (as you
mention in your post). By convention, this node contains
application-specific error information. The CustomException method builds
the Detail node and adds three child nodes, each containing an important
piece of information from the original exception. The three items of
information specified here are the original exception type, the original
exception message, and the original exception stack trace. Once these child
nodes have been created, they're added to the Detail node, and then the
custom SoapException is built. The constructor that I'm using to create the
new exception contains four arguments:

1) Message: This is left blank, because the Web service will populate it
automatically before the exception reaches the client. You aren't really
interested in this message because it doesn't provide useful information in
an easily accessible way.
2) Code: This contains one of four predefined SOAP codes. Here it's being
populated with the ServerFaultCode, signifying that the problem lies with
the code inside the Web service.
3) Actor: By convention, this argument contains the URL of the Web service
that caused the error.
4) Detail: This node contains the application-specific information that I'm
interested in, namely the details that I grabbed from the original
exception.

HTH,

Mark
--
Author of "Comprehensive VB .NET Debugging"
http://www.apress.com/book/bookDisplay.ht...

Private Function CustomException(ByVal Exc As Exception) As SoapException

'Create detail node
Dim doc As New System.Xml.XmlDocument
Dim DetailNode As System.Xml.XmlNode = doc.CreateNode(XmlNodeType.Element, _

SoapException.DetailElementName.Name, _

SoapException.DetailElementName.Namespace)

'Add original exception type
Dim ExcType As System.Xml.XmlNode = doc.CreateNode(XmlNodeType.Element, _

"ExceptionType", _

SoapException.DetailElementName.Namespace)
ExcType.InnerText = Exc.GetType.ToString

'Add original exception message
Dim ExcMessage As System.Xml.XmlNode = doc.CreateNode(XmlNodeType.Element, _

"ExceptionMessage", _

SoapException.DetailElementName.Namespace)
ExcMessage.InnerText = Exc.Message

'Add original exception stack trace
Dim ExcStackTrace As System.Xml.XmlNode =
doc.CreateNode(XmlNodeType.Element, _

"ExceptionTrace", _

SoapException.DetailElementName.Namespace)
ExcStackTrace.InnerText =Exc.StackTrace

'Append the extra details to main detail node
DetailNode.AppendChild(ExcType)
DetailNode.AppendChild(ExcMessage)
DetailNode.AppendChild(ExcStackTrace)

'Build and return new custom SoapException
Return New SoapException("", SoapException.ServerFaultCode, _
Context.Request.Url.AbsoluteUri,
DetailNode)

End Function

"Chris Woodcock" <chris@gcssltd.co.uk> wrote in message
news:OQecgcgSDHA.1684@TK2MSFTNGP11.phx.gbl...
Hi,

I am trying to catch an exception in a WebMethod and then throw a
SoapException with the original exception serialized inside it.

I have tried two techniques.

1) Using the SoapFormatter to serialize the original exception, which allows
me to create an XmlNode for the detail parameter.

This is OKuntil the SoapException is thrown, but on the client side an
XmlReader exception is throw when the SoapException itself is deserializied.
I assume the SOAP markup cannot be read by an XmlReader (I had to use a
SoapFormatter on the server).

Can this be worked around, I'm a beginer with XML, so maybe I'm missing
something obvioius?

2) After serializing the original exception as a string I include it as the
Message parameter to the SoapException.

However when I attempt to deserialize this there is a stack trace inserted
on the end. When I use CustomErrors="On" in web.config the stack trace is
removed but the markup tags are converted into "&lt;" and "&gt;" and others
for example.

Is there a way of translating it back automatically or stopping this
'feature' from occurring?

3) Using a custom wrapper around the actual text and then use
CustomError="Off", I can then parse the wanted markup on the client, but
this not very satisfactory, but atleast it works!.

Regards

Chris Woodcock.