locked
How to troubleshoot DataServicesReqestException on post? RRS feed

  • Question

  • I am getting DataServicesReqquestException during saving the changes Status code is 500. Is Fiddler the only way to troubleshoot it? I tried:

    config.UseVerboseErrors = true;
    

    and

    <serviceBehaviors>
            <behavior name="DataServiceBehavior">
              <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
          </serviceBehaviors>
    

    But that didn't help..

     

    -Stan

    Monday, September 19, 2011 6:52 PM

All replies

  • Hi Stan,

    In general, Fiddler is very useful for debugging these kinds of issues. Even with verbose errors and include..., the client will very likely throw a general error which just contains the server-side error in the message. Is that not happening? Or are you hoping for a more descriptive exception type/message?

    If you'd like to reply with the contents of the response, I'd be happy to help you figure out the root cause.


    Matt Meehan (WCF Data Services / OData)
    Tuesday, September 20, 2011 3:55 AM
    Moderator
  • Matt:

    Here is what's happening:

    Domain object (note that CategoryId is mapped to the foreign key field with possible values 1, 2, 3, 4 and so on)

    public class StockItem
    {
            public int Id { get; set; }
            public int CategoryId { get; set; }
            public virtual Category Category { get; set; }
            public string Name { get; set; }
            public byte[] Picture { get; set; }
    }
    

    EF 4.1 Code-FirstContext

    public class StoreContext : DbContext, IDisposable
    {
            public DbSet<StockItem> StockItems { get; set; }
    }
    

    Service:

    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]  
     public class StoreService : DataService<StoreContext>
    {
            public static void InitializeService(DataServiceConfiguration config)
            {
                config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
                config.UseVerboseErrors = true;
                config.SetEntitySetAccessRule("StockItems", EntitySetRights.All);
            }
    }
    

    On WFP client service proxy is wrapped into DataServiceCollection:

    public DataServiceCollection<StockItem> GetStockItems()
    {            
                return new DataServiceCollection<StockItem>(_context.StockItems);            
     }
    
    

    WPF client binds grid to these items. Now here are the steps:

    1. New row added to the grid on client, but no values entered

    2. New uninitialized value added to DataServiceCollection. This new value so far has CategoryId of 0

    3. Save button on the client is clicked

    5. SaveChanges is executed

    6. Service is trying to save entity and fails because of foreign key violation

    7. Service returns generic 500 error to the client

    8. Client wraps it into DataServiceException.

    "Fixing it" is simple - initialize the new entity or prevent saving of incomplete data. I understand that. My question is  about troubleshooting the exceptions like that in the framework. Here is what I don't understand. When the service dies at step 6, is it possible to at least log the complete error if propagating it back to the client over REST is problematic? Imagine that it is somebody else's code and you're getting HTTP 500, how can you possibly find what's wrong?

    -Stan

     

     

     

    Tuesday, September 20, 2011 12:51 PM
  • Hi Stan,

    I understand actually you have found out the resolution for this error. You are just wondering if there are any normal tools or methods for troubleshooting this kind of issue. Actually it's totally case by case. Anyway, there are some normal steps you can use to troubleshooting WCF issue:

    1. You can enable WCF trace & message log on both client and service side. More details about WCF trace, you can reference to below article:

    http://msdn.microsoft.com/en-us/library/ms733025.aspx>

     

    and then use svctraceviewer.exe to analyze the log.

    2. You can  use WCFtestclient tool to test your WCF service.

    3. or write log near the suspicious place.

    Wednesday, September 28, 2011 7:47 AM
  • Hi Winston,

    So far Firdler is the only way of resolving service-side problems. I was just wondering why exception details captured by the Fidler are not part of DataServiceException..  The serivice sends back all error details in 500 message, but for some reasons they don't make it all the way..

    -Stan

     


    • Edited by Stan B Friday, September 30, 2011 7:57 PM
    Friday, September 30, 2011 7:56 PM