Thursday, July 25, 2013

Enable Verbosely Errors in WCF Data Service

In case you want to see some additional info about the occurred exception (+ its stack trace). There are 3 ways to do this:
  1. You can change your service configuration in InitializeService() method
        
    
        public class MrSophisticatedServer: DataService<TestEntities>
        {
            public static void InitializeService(DataServiceConfiguration config)
            {
                // Make service to report errors in a nice way - doesn't really help....
                config.UseVerboseErrors = true;
    
               ....
          
            }
        }
    
    
    NOTE: There is one problem with this method. It does not work if your service (for some ridiculous reason) is not initialized. Basically, something goes wrong before InitializeService() is called. In this case use method 2 or 3 below.

  2. Add this attribute before your data service class
    
        [System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)] 
    
    

  3. Add the following to your Web.config
     
    
    
        
          
          
        
        
          
            
              
            
          
        
        
         
    
    
    
    Basically, this also sets IncludeExceptionDetailInFaults to TRUE. You define service behavior and ask your smart-ass computer to use it for your service.

No comments:

Post a Comment