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:




//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);


Comments (3)

  1. Vishal says:

    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.

  2. ceibner says:

    Thanks for the extra details Vishal 🙂

    Much appreciated,

    Catherine Eibner