locked
CRM 2011 - Exception Handling in Silverlight with Soap End-Point RRS feed

  • Question

  • When an exception occurs from the Soap End-Point, a standard CommunincationException is thrown.

    Is there a way to access the exception message thrown by the OrganizationService?

    -Luke Baulch

    Tuesday, September 6, 2011 8:08 AM

Answers

  • Handling service exceptions in Silverlight takes a little extra effort. The following is a typical way that has been used in SDK to handle such service exceptions. 

    try
    {                 
        accounts.BeginExecute(OnRetrieveAccountsComplete, accounts); 
    }
    catch (DataServiceQueryException dsqe)
    {
        _syncContext.Send(new SendOrPostCallback(showErrorDetails), dsqe);
    }
    
    


    showErrorDetails is a method that you use to update UI components with the exception information that you have captured. 

    You can find samples from sdk\samplecode\cs\silverlight\crmodatasilverlight folder. 

    Hope this helps. 


    Daniel Cai | http://danielcai.blogspot.com
    • Marked as answer by Luke Baulch Tuesday, October 25, 2011 5:46 AM
    Wednesday, September 7, 2011 4:14 AM

All replies

  • Hi,

    You can access the exception message like:

    try

    {

        // Service Call

     

     }

    catch (System.Web.Services.Protocols.SoapException ex)

    {

                   alert(ex.Detail.InnerText);

    }

    catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> ex)

    {

     

     

    ServiceFault fault = ex.Detail;

    alert(fault.MessageText);

       

    }

     

    catch (FaultException<ServiceFault> ex)

    {

    ServiceFault fault = ex.Detail;

    alert(fault.MessageText);

    }

     

     


    Jehanzeb Javeed

    http://worldofdynamics.blogspot.com
    Linked-In Profile |CodePlex Profile

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Tuesday, September 6, 2011 8:29 AM
  • Does this work in Silverlight as the question states?

    When something fails, I get a CommunicationException with the message "The remote server returned an error: NotFound.". Therefore, there is no Detail property in the exception to retrieve further information regarding the error.

    Tuesday, September 6, 2011 11:48 PM
  • The uri you connected is correct?
    daemon lin
    Wednesday, September 7, 2011 2:05 AM
  • The uri is fine.

    When I use Fiddler I can see the error message in OrganizationService exception. But I can't seem to get access to that message from within Silverlight.

    -Luke Baulch

    Wednesday, September 7, 2011 3:09 AM
  • Handling service exceptions in Silverlight takes a little extra effort. The following is a typical way that has been used in SDK to handle such service exceptions. 

    try
    {                 
        accounts.BeginExecute(OnRetrieveAccountsComplete, accounts); 
    }
    catch (DataServiceQueryException dsqe)
    {
        _syncContext.Send(new SendOrPostCallback(showErrorDetails), dsqe);
    }
    
    


    showErrorDetails is a method that you use to update UI components with the exception information that you have captured. 

    You can find samples from sdk\samplecode\cs\silverlight\crmodatasilverlight folder. 

    Hope this helps. 


    Daniel Cai | http://danielcai.blogspot.com
    • Marked as answer by Luke Baulch Tuesday, October 25, 2011 5:46 AM
    Wednesday, September 7, 2011 4:14 AM