Multimobile Development: Building Applications for any Smartphone
Error Handling Continued
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngwebservices' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Stephen Miller
There have been a number of posts on error handling lately and I wondered
what people thought of raising custom errors within their web services and
then the best way of catching the exception? I use the following function to
raise SoapExceptions:

Public Shared Sub ThrowCustomException(ByVal sMsg As String, _
ByVal FaultCode As XmlQualifiedName, _
ByVal ProcName As String, _
ByVal Action As String, _
ByVal sNamespace As String)

Dim oDoc As New System.Xml.XmlDocument()
Dim oProcedure As System.Xml.XmlNode
Dim oAction As System.Xml.XmlNode
Dim oDetail As System.Xml.XmlNode =
oDoc.CreateNode(XmlNodeType.Element, _
SoapException.DetailElementName.Name, _
SoapException.DetailElementName.Namespace)
oDetail.InnerText = sMsg

'The procedure that failed
oProcedure = oDoc.CreateNode(XmlNodeType.Element, "Procedure",
sNamespace)
oProcedure.InnerText = ProcName
'the action the client should take
oAction = oDoc.CreateNode(XmlNodeType.Element, "Action", sNamespace)
oAction.InnerText = Action

oDetail.AppendChild(oProcedure)
oDetail.AppendChild(oAction)

'throw the exception
Dim oEx As New SoapException(sMsg, FaultCode, "", oDetail)
Throw oEx
Return
End Sub

The problem when I catch the SoapException on the client the detail element
has the following innerXML:

InnerXml: "Some message here<Procedure xmlns="http://test.com/test.xsd";>Some
function here</Procedure><Action xmlns="http://test.com/test.xsd";>Tell the
client what to do</Action>"

Is there a neater way of accessing the innerText of the detail element
rather than the following line of code:

sError = oSOAPEx.Detail.ChildNodes(0).InnerText

Thanks guys,
Stephen Miller

Reply to this message...
Vote that this is a GOOD answer...
 
Really good experience at the Apple Store
MonoDroid – looking *awesome*
 
    
Kollen Glynn
Essentially you want something along the lines of:

sError = oSOAPEx.Detail.SelectSingleNode("descendant::msg").InnerText

Where the detail element looks something like this:
<detail>
<msg>Some message</msg>
<procedure>MyProc</procedure>
<action>Give_Up</action>
</detail>

-----Original Message-----
From: Stephen Miller [mailto:Click here to reveal e-mail address]
Sent: Monday, February 18, 2002 2:31 PM
To: aspngwebservices
Subject: [aspngwebservices] Error Handling Continued

There have been a number of posts on error handling lately and I
wondered
what people thought of raising custom errors within their web services
and
then the best way of catching the exception? I use the following
function to
raise SoapExceptions:

Public Shared Sub ThrowCustomException(ByVal sMsg As String, _
ByVal FaultCode As XmlQualifiedName, _
ByVal ProcName As String, _
ByVal Action As String, _
ByVal sNamespace As String)

Dim oDoc As New System.Xml.XmlDocument()
Dim oProcedure As System.Xml.XmlNode
Dim oAction As System.Xml.XmlNode
Dim oDetail As System.Xml.XmlNode =
oDoc.CreateNode(XmlNodeType.Element, _
SoapException.DetailElementName.Name, _
SoapException.DetailElementName.Namespace)
oDetail.InnerText = sMsg

'The procedure that failed
oProcedure = oDoc.CreateNode(XmlNodeType.Element, "Procedure",
sNamespace)
oProcedure.InnerText = ProcName
'the action the client should take
oAction = oDoc.CreateNode(XmlNodeType.Element, "Action",
sNamespace)
oAction.InnerText = Action

oDetail.AppendChild(oProcedure)
oDetail.AppendChild(oAction)

'throw the exception
Dim oEx As New SoapException(sMsg, FaultCode, "", oDetail)
Throw oEx
Return
End Sub

The problem when I catch the SoapException on the client the detail
element
has the following innerXML:

InnerXml: "Some message here<Procedure
xmlns="http://test.com/test.xsd";>Some
function here</Procedure><Action xmlns="http://test.com/test.xsd";>Tell
the
client what to do</Action>"

Is there a neater way of accessing the innerText of the detail element
rather than the following line of code:

sError = oSOAPEx.Detail.ChildNodes(0).InnerText

Thanks guys,
Stephen Miller

| [aspngwebservices] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngwebservices.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

Reply to this message...
Vote that this is a GOOD answer...
 
First volume of Multimobile Development nearly ready to go to press
A mention on Developing for the iPhone and Android: The pros and cons
 
    
Bob Levittan (VIP)
If you mean expected errors, I do it by trapping the error in the web
service code, and including error code and error message elements in the
returned xml document.

----Original Message Follows----
From: "Kollen Glynn" <Click here to reveal e-mail address>
Reply-To: "aspngwebservices" <Click here to reveal e-mail address>
To: "aspngwebservices" <Click here to reveal e-mail address>
Subject: [aspngwebservices] RE: Error Handling Continued
Date: Mon, 18 Feb 2002 14:56:38 -0800

Essentially you want something along the lines of:

sError = oSOAPEx.Detail.SelectSingleNode("descendant::msg").InnerText

Where the detail element looks something like this:
<detail>
<msg>Some message</msg>
<procedure>MyProc</procedure>
<action>Give_Up</action>
</detail>

-----Original Message-----
From: Stephen Miller [mailto:Click here to reveal e-mail address]
Sent: Monday, February 18, 2002 2:31 PM
To: aspngwebservices
Subject: [aspngwebservices] Error Handling Continued

There have been a number of posts on error handling lately and I
wondered
what people thought of raising custom errors within their web services
and
then the best way of catching the exception? I use the following
function to
raise SoapExceptions:

Public Shared Sub ThrowCustomException(ByVal sMsg As String, _
ByVal FaultCode As XmlQualifiedName, _
ByVal ProcName As String, _
ByVal Action As String, _
ByVal sNamespace As String)

Dim oDoc As New System.Xml.XmlDocument()
Dim oProcedure As System.Xml.XmlNode
Dim oAction As System.Xml.XmlNode
Dim oDetail As System.Xml.XmlNode =
oDoc.CreateNode(XmlNodeType.Element, _
SoapException.DetailElementName.Name, _
SoapException.DetailElementName.Namespace)
oDetail.InnerText = sMsg

'The procedure that failed
oProcedure = oDoc.CreateNode(XmlNodeType.Element, "Procedure",
sNamespace)
oProcedure.InnerText = ProcName
'the action the client should take
oAction = oDoc.CreateNode(XmlNodeType.Element, "Action",
sNamespace)
oAction.InnerText = Action

oDetail.AppendChild(oProcedure)
oDetail.AppendChild(oAction)

'throw the exception
Dim oEx As New SoapException(sMsg, FaultCode, "", oDetail)
Throw oEx
Return
End Sub

The problem when I catch the SoapException on the client the detail
element
has the following innerXML:

InnerXml: "Some message here<Procedure
xmlns="http://test.com/test.xsd";>Some
function here</Procedure><Action xmlns="http://test.com/test.xsd";>Tell
the
client what to do</Action>"

Is there a neater way of accessing the innerText of the detail element
rather than the following line of code:

sError = oSOAPEx.Detail.ChildNodes(0).InnerText

Thanks guys,
Stephen Miller

| [aspngwebservices] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngwebservices.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

| [aspngwebservices] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngwebservices.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Stephen Miller
Bob,

Can you provide examples of how you have structured your error handling on
the server? Suppose from your public method you end up in a function 6
levels deep, do you just 'throw exception' at that level or do you call a
custom function like the one I posted? I am trying to find out the best way
of processing server and client errors and then throwing them as
SoapExceptions. Does anyone else have good ideas/resources?

Cheers,
Stephen Miller

-----Original Message-----
From: Bob Levittan [mailto:Click here to reveal e-mail address]
Sent: 19 February 2002 02:22
To: aspngwebservices
Subject: [aspngwebservices] RE: Error Handling Continued

If you mean expected errors, I do it by trapping the error in the web
service code, and including error code and error message elements in the
returned xml document.

----Original Message Follows----
From: "Kollen Glynn" <Click here to reveal e-mail address>
Reply-To: "aspngwebservices" <Click here to reveal e-mail address>
To: "aspngwebservices" <Click here to reveal e-mail address>
Subject: [aspngwebservices] RE: Error Handling Continued
Date: Mon, 18 Feb 2002 14:56:38 -0800

Essentially you want something along the lines of:

sError = oSOAPEx.Detail.SelectSingleNode("descendant::msg").InnerText

Where the detail element looks something like this:
<detail>
<msg>Some message</msg>
<procedure>MyProc</procedure>
<action>Give_Up</action>
</detail>

-----Original Message-----
From: Stephen Miller [mailto:Click here to reveal e-mail address]
Sent: Monday, February 18, 2002 2:31 PM
To: aspngwebservices
Subject: [aspngwebservices] Error Handling Continued

There have been a number of posts on error handling lately and I
wondered
what people thought of raising custom errors within their web services
and
then the best way of catching the exception? I use the following
function to
raise SoapExceptions:

Public Shared Sub ThrowCustomException(ByVal sMsg As String, _
ByVal FaultCode As XmlQualifiedName, _
ByVal ProcName As String, _
ByVal Action As String, _
ByVal sNamespace As String)

Dim oDoc As New System.Xml.XmlDocument()
Dim oProcedure As System.Xml.XmlNode
Dim oAction As System.Xml.XmlNode
Dim oDetail As System.Xml.XmlNode =
oDoc.CreateNode(XmlNodeType.Element, _
SoapException.DetailElementName.Name, _
SoapException.DetailElementName.Namespace)
oDetail.InnerText = sMsg

'The procedure that failed
oProcedure = oDoc.CreateNode(XmlNodeType.Element, "Procedure",
sNamespace)
oProcedure.InnerText = ProcName
'the action the client should take
oAction = oDoc.CreateNode(XmlNodeType.Element, "Action",
sNamespace)
oAction.InnerText = Action

oDetail.AppendChild(oProcedure)
oDetail.AppendChild(oAction)

'throw the exception
Dim oEx As New SoapException(sMsg, FaultCode, "", oDetail)
Throw oEx
Return
End Sub

The problem when I catch the SoapException on the client the detail
element
has the following innerXML:

InnerXml: "Some message here<Procedure
xmlns="http://test.com/test.xsd";>Some
function here</Procedure><Action xmlns="http://test.com/test.xsd";>Tell
the
client what to do</Action>"

Is there a neater way of accessing the innerText of the detail element
rather than the following line of code:

sError = oSOAPEx.Detail.ChildNodes(0).InnerText

Thanks guys,
Stephen Miller

| [aspngwebservices] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngwebservices.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

| [aspngwebservices] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngwebservices.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.

| [aspngwebservices] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngwebservices.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

Reply to this message...
Vote that this is a GOOD answer...
 
First chapters of Multimobile Development book now available on Apress Alpha program
iPad
 
 
System.Web.Services.Protocols.SoapException
System.Xml.XmlDocument
System.Xml.XmlNode
System.Xml.XmlNodeType
System.Xml.XmlQualifiedName




Ad
BootFX
Reliable and powerful .NET application framework.
iOS, Android and Windows Phone Development Training and Consultancy
Hosted by RackSRV Communications
 
Multimobile Development: Building Applications for any Smartphone
Copyright © AMX Software Ltd 2008-2010. Portions copyright © Matthew Baxter-Reynolds 2001-2010. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - 4.0.30129.1734