Devido o CRM ser baseado em SOAP muitas exceptions acabam tendo seu verdadeiro erro ofuscado por um “Server was unable to process request.” (que muito nos ajuda!). Uma alternativa bastante utilizada seria habilita o trace e ver o log de erros, porém existe uma forma mais visual e simples que pode ser adaptada e melhorada, mas o quero deixar é o conceito mesmo.
... // Dll SOAP Exception using System.Web.Services.Protocols; ... ... // contactGuid is the GUID of the record being deleted -Since this is a random GUID, it should not exist in theMicrosoft Dynamics CRM system against which this code isrun Guid contactGuid = new Guid("4D507FFE-ED25-447B-80DE-00AE3EB18B84"); try { // Delete the non-existent Contact INSTANCIA_WEB_SERVICE.Delete(EntityName.contact.ToString(), contactGuid); } catch (SoapException ex) { // This will contain the error message from the platform Response.Write("Microsoft Dynamics CRM Error Information:" + " "); Response.Write(ex.Detail.InnerText + " "); // The InnerXml contains the details of the error in aparsable XML format XmlDocument error = new XmlDocument(); error.LoadXml(ex.Detail.InnerXml); // Render out the details of the error Response.Write("Error Code: " + error.SelectSingleNode("/error/code").InnerText + " "); Response.Write("Error Description: " + error.SelectSingleNode("/error/description").InnerText + " "); Response.Write("Error Type: " + error.SelectSingleNode("/error/type").InnerText + " "); } ...
Este código foi retirado e adaptado do curso preparatório “8969A Extending Microsoft Dynamics CRM 4.0” .