Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / June 2004

Tip: Looking for answers? Try searching our database.

How to handle common/routine exceptions?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
IanT - 09 Jun 2004 06:04 GMT
There seems to be common agreement that all Web Service exceptions
should be passed to the client as a SoapException. I do this but even
when raising a custom soap exception the throw command returns
information about private methods/line numbers etc.

While this is OK for unhandled exceptions it seems messy for errors
such as "User not logged in.". Is there a way of throwing a
SoapException which doesn't provide this additional information to the
client? Maybe i'm being petty but i can't imagine getting a login
failure message from a commercial microsoft web service that gives me
the line number the error was thrown from.

Is this how other developers are handling these exceptions? If it's
the best practice i have no real problem with it - it just doesn't
seem quite right.

any comments appreciated.

Ian

--Error Message being returned--
System.Web.Services.Protocols.SoapException: Not logged in.
  at SSRAUploadWebService.RAService.CheckLoggedIn() in
c:\inetpub\wwwroot\SSRAUpload\RAService.asmx.vb:line 81
  at SSRAUploadWebService.RAService.UploadBatch(XmlDocument XMLDoc)
in c:\inetpub\wwwroot\SSRAUpload\RAService.asmx.vb:line 111"

--Code used to throw Exception--

Private Function CheckLoggedIn() As Boolean
       If (sessionLoginSecurity Is Nothing) OrElse
sessionLoginSecurity.IsLoggedIn = False Then
           Throw RaiseException("checkLoggedIn", "Not logged in.",
errorCodes.NotLoggedIn, "", FaultCode.Client)
       End If

   End Function

Public Function RaiseException(ByVal uri As String, _
                   ByVal errorMessage As String, _
                   ByVal errorNumber As errorCodes, _
                   ByVal errorSource As String, _
                   ByVal code As FaultCode) As SoapException

       Dim webServiceNamespace As String =
"http://flexirent.com/webServices/SSRAUpload/RAService.asmx"
       Dim faultCodeLocation As XmlQualifiedName
       'Identify the location of the FaultCode
       Select Case code
           Case FaultCode.Client
               faultCodeLocation = SoapException.ClientFaultCode

           Case FaultCode.Server
               faultCodeLocation = SoapException.ServerFaultCode
       End Select

       Dim xmlDoc As XmlDocument = New XmlDocument

       'Create the Detail node
       Dim rootNode As XmlNode =
xmlDoc.CreateNode(XmlNodeType.Element, _
                                                 
SoapException.DetailElementName.Name, _
                                                 
SoapException.DetailElementName.Namespace)

       'Build specific details for the SoapException
       'Add first child of detail XML element.
       Dim errorNode As XmlNode =
xmlDoc.CreateNode(XmlNodeType.Element, "Error", webServiceNamespace)

       'Create and set the value for the ErrorNumber node
       'Dim errorNumberNode As XmlNode =
xmlDoc.CreateNode(XmlNodeType.Element, "ErrorNumber",
webServiceNamespace)
       'errorNumberNode.InnerText = errorNumber

       'Create and set the value for the ErrorMessage node
       Dim errorMessageNode As XmlNode =
xmlDoc.CreateNode(XmlNodeType.Element, "ErrorMessage",
webServiceNamespace)
       errorMessageNode.InnerText = errorMessage

       'Create and set the value for the ErrorSource node
       Dim errorSourceNode As XmlNode =
xmlDoc.CreateNode(XmlNodeType.Element, "ErrorSource",
webServiceNamespace)
       errorSourceNode.InnerText = errorSource

       'Append the Error child element nodes to the root detail node.
       'errorNode.AppendChild(errorNumberNode)
       errorNode.AppendChild(errorMessageNode)
       errorNode.AppendChild(errorSourceNode)

       'Append the Detail node to the root node
       rootNode.AppendChild(errorNode)

       'Construct the exception
       Dim soapEx As SoapException = New SoapException(errorMessage,
faultCodeLocation, uri, rootNode)

       'Raise the exception  back to the caller
       Return soapEx

   End Function
Jan Tielens - 09 Jun 2004 06:20 GMT
You may want to read following articles:
http://www.microsoft.com/belux/nl/msdn/community/columns/jtielens/soapexceptions.mspx
http://msdn.microsoft.com/library/en-us/dnservice/html/service09172002.asp

The last one explains how to hide the line numbers etc.

Signature

Greetz
Jan
________________
Read my weblog: http://weblogs.asp.net/jan

> There seems to be common agreement that all Web Service exceptions
> should be passed to the client as a SoapException. I do this but even
[quoted text clipped - 101 lines]
>
>     End Function
IanT - 17 Jun 2004 02:06 GMT
> The last one explains how to hide the line numbers etc.

many thanks.

<customErrors mode="RemoteOnly" />

was the answer. I had seen this elsewhere but had somehow not got the
desired result in the past.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.