Welcome to Atlanta .NET Regular Guys Sign in | Join | Help

Fiddler and SoapExceptions

Jim Wooley posted about how he informed me that this great HTTP analyzer tool called Fiddler existed.  This let me look into my code's exceptions to figure out what was happening.  He posted about the existance of the tool and how it's a great thing.  I thought I should post my specific example, what it showed me and what I learned from it.

I'm writing some code that access the SharePoint 2007 web services.  My code is trying to call the AddUserToGroup web method located at http://localhost/_vti_bin/UserGroup.asmx.  The proxy method call requires two string parameters - user LoginName and Group Name.  (Actually the method requires 5 parameters, but these 2 are the only ones verified against the system).  I was passing a valid AD user login name and a valid group name, but my call to the web service was getting a Microsoft.SharePoint.SoapServer.SoapServerException.  The problem was that I couldn't find the actual details of what the error really was.  The Exception.InnerException was null and the Exception.Message just said that a SoapServerException occurred.  The stack trace was useless as it just showed me the line of the reference class that was experiencing the exception.  How the heck could I tell what was actually causing the exception?

Fiddler to the rescue.  I opened that bad boy up and got the following feedback:

The SOAP envelope contains an error string which told me that my username did not exist.  Now, how do I get that value in my code so I can react to it?

Once I knew what I was looking for, I implemented the following code to log a descriptive error to the eventlog.  If I can, I cast the general exception message to a SoapException and get the SoapException.Detail.InnerText. 

// create an event log source called Extranet if it doesn't exist
if (!EventLog.SourceExists("Extranet"))
{
EventLog.CreateEventSource("Extranet", "Application");
} 

// create an eventlog object to handle writing errors to the event log
EventLog log = new EventLog("Application");
log.Source = "Extranet" 

// build the event log error message
StringBuilder errorMessage = new StringBuilder("Error: ");
errorMessage.Append(ex.GetType().Name + Environment.NewLine); 

// try to cast the exception to a soap exception so we can get useful info
try
{
SoapException sexp = (SoapException)(ex);
errorMessage.Append("Soap Envelope error details: " + Environment.NewLine);
errorMessage.Append(sexp.Detail.InnerText);
}
catch (Exception)
{ 
// just log the original details
}
// continue appending details to the exception log message
errorMessage.Append("User details - SharePoint Group Names: " + Environment.NewLine);
errorMessage.Append(userDetails.groupNames + Environment.NewLine);
errorMessage.Append("User details - User Name: " + Environment.NewLine);
errorMessage.Append(userDetails.userName + Environment.NewLine);
errorMessage.Append("User details - User LoginName: " + Environment.NewLine);
errorMessage.Append(userDetails.userLoginName + Environment.NewLine);
errorMessage.Append("Stack Trace: " + Environment.NewLine);
errorMessage.Append(ex.StackTrace);
errorMessage.Append("Message: " + Environment.NewLine);
errorMessage.Append(ex.Message); 

// write the error to the event log
log.WriteEntry(errorMessage.ToString());
 
Published 26-10-2006 07:53 by Matt Ranlett
Filed Under: , ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

cheap loan said:

QLBZ5  http://gaestebuch4u.de/gb/Edirewan.html mortgage refinance [url=http://gaestebuch4u.de/gb/freierpoker.html]mortgage[/url] mortgage <a href="http://daddelnews.de/news_details.php3">mortgage refinance</a> mortgage refinance
April 14, 2007 8:32 AM

What do you think?

(required) 
(optional)
(required) 

About Matt Ranlett

One of the two original Atlanta .NET Regular Guys, Matt fills his free time by helping to run several Atlanta area user groups, the Atlanta Code Camps, and works as one of the two INETA co-Vice Presidents of Technology
SkinName:iroha_Blog2
Powered by Community Server, by Telligent Systems