Welcome to MSDN Blogs Sign in | Join | Help

Catherine Eibner

Dynamics, SQL, .Net & getting them all to play nicely together!
CRM Webservice Soap Exception Helper Code

I am currently working through some of the great content created for the Business Action World Tour training sessions, and as part of that, playing with the great Labs that have been created.

I just came across some code that helps to give you a bit more information when you hit a Soap Error when connecting to the CRM Web services. I think its a great way to bubble up that bit more information about what caused the error to the developer (and any error logging you may be doing as well) & help you work out what has happened, so thought I would share it:

 

try

{

//do something here that tries to use the CRM Webservice

}

catch (SoapException ex)

{

string errorMessage = ex.Message;

if(ex.Detail != null)

{

// If there is a InnerText message then we will overwrite with this instead. It can be

// more helpful to explain the error.

errorMessage = ((System.Xml.XmlElement)ex.Detail).InnerText;

}

throw new Exception("Something went wrong when communication with the Web Service. Error: " + errorMessage);

}

Posted: Thursday, May 28, 2009 3:24 PM by ceibner

Comments

Vishal said:

1) SoapException An XML Web service method detects an exception case and throws a SoapException. It also provides additional details regarding the problem. The XML Web service method populates the Detail property to provide this additional information. An ASP.NET client receives the SoapException with the additional information.

2) SoapHeaderException An XML Web service method detects an exception case while processing a SOAP header. The XML Web service method must throw a SoapHeaderException back to the client, according to the SOAP specification. An ASP.NET client receives the SoapHeaderException.

# October 12, 2009 4:02 AM

ceibner said:

Thanks for the extra details Vishal :)

Much appreciated,

Catherine Eibner

http://blogs.msdn.com/ceibner

# October 12, 2009 4:45 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

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

Page view tracker