Handling SOAP Exceptions In Microsoft Dynamics CRM

Posted: January 20, 2009 in Microsoft Dynamics CRM
Tags: ,

The only exception thrown by the CRM Web service is a common

SoapException whose message property is always “Server was unable to process

request.”

 

To handle that exception, catch the exception and display the InnerXml error

code, error text, and error description

 

Example

 

try

{

// Delete the non-existent Contact

service.Delete(EntityName.contact.ToString(), contactGuid);

}

catch (SoapException ex)

{

// This will contain the error message from the platform

Console.WriteLine(“Microsoft Dynamics CRM Error

Information:”);

Console.WriteLine(ex.Detail.InnerText);

// The InnerXml contains the details of the error in a

parsable XML format

XmlDocument error = new XmlDocument();

error.LoadXml(ex.Detail.InnerXml);

// Render out the details of the error

Console.WriteLine(“Error Code: ” +

error.SelectSingleNode(“/error/code”).InnerText);

Console.WriteLine(“Error Description: ” +

error.SelectSingleNode(“/error/description”).InnerText);

Console.WriteLine(“Error Type: ” +

error.SelectSingleNode(“/error/type”).InnerText);

}

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s