locked
Can query WCF Data Service, but cannot Save Changes RRS feed

  • Question

  • Hi There,

    I have a WCF data service that works great for querying - I can return data from my source system using the data service. However, I cannot update or create an instance of any of the entities in my data source. The best error I can get is "an error occurred while processing this request."

    The data service configuration has EntitySetRights.All and ServiceOperationRights.All. I'm stuck in my troubleshooting - can anyone guide me? Code below. Thanks!

     

    account a = new account(); 
    
    a.name = "From Code"; 
    
     
    
    svc.AddObject("accounts", a); 
    
    svc.BeginSaveChanges(SaveChangesOptions.Batch, on_update, svc); 
    
     
    
    public void on_update(IAsyncResult ar) 
    
            { 
    
                Dispatcher.BeginInvoke(() => 
    
                    { 
    
                        svc = ar.AsyncState as DataContext; 
    
     
    
                      
    
                        WriteOperationResponse(svc.EndSaveChanges(ar)); 
    
                       
    
                    } 
    
                ); 
    
            } 
    
     
    
            private void WriteOperationResponse(DataServiceResponse response) 
    
            { 
    
                string messageTextBlock = string.Empty; 
    
                int i = 1; 
    
     
    
                if (response.IsBatchResponse) 
    
                { 
    
                    messageTextBlock = string.Format("Batch operation response code: {0}\n", 
    
                        response.BatchStatusCode); 
    
                } 
    
                foreach (ChangeOperationResponse change in response) 
    
                { 
    
                    messageTextBlock += 
    
                        string.Format("\tChange {0} code: {1}\n", 
    
                        i.ToString(), change.StatusCode.ToString()); 
    
                    if (change.Error != null) 
    
                    { 
    
                        messageTextBlock += 
    
                        string.Format("\tChange {0} error: {1}\n", 
    
                            i.ToString(), change.Error.Message); 
    
                    } 
    
                    i++; 
    
                } 
    
            }


     

     


    Web: http://invoc.net Blog: http://invoc.net/CRM_BPOS_Blog
    Friday, July 30, 2010 12:53 PM

Answers

  • Hi,

    This is unlikely to be a problem with you client code. To get a more detailed error message please follow the instructions on this blog by Phani: http://blogs.msdn.com/b/phaniraj/archive/2008/06/18/debugging-ado-net-data-services.aspx

    What provider do you use on the server? (Entity Framework, Reflection, custom, ...)

    WCF Data Services only supports write operation out of the box on the Entity Framework provider. For all other providers you need to implement the IUpdatable/IDataServiceUpdateProvider interface.

    Thanks,


    Vitek Karas [MSFT]
    Friday, July 30, 2010 6:47 PM
    Moderator
  • Hi,

    Well it feels like a problem with the CRM classes. In any case, just by the exception message there's not much I can do. If you could provide the request you're trying to make and the full callstack of the exception, it would help. But I would probably go ask on the CRM forums instead as they will likely know more about this issue.

    Thanks,


    Vitek Karas [MSFT]
    Tuesday, August 3, 2010 8:18 AM
    Moderator

All replies

  • Hi,

    This is unlikely to be a problem with you client code. To get a more detailed error message please follow the instructions on this blog by Phani: http://blogs.msdn.com/b/phaniraj/archive/2008/06/18/debugging-ado-net-data-services.aspx

    What provider do you use on the server? (Entity Framework, Reflection, custom, ...)

    WCF Data Services only supports write operation out of the box on the Entity Framework provider. For all other providers you need to implement the IUpdatable/IDataServiceUpdateProvider interface.

    Thanks,


    Vitek Karas [MSFT]
    Friday, July 30, 2010 6:47 PM
    Moderator
  • Hi Vitek,

    Thanks so much for your reply! I tracked down an inner exception using the method you linked to - a System.Data.Services.Client.DataServiceClientException with the message:

    "Property set method not found." 

    The entity classes and context contained in my data service were created by a svcutil.exe utility, so I don't know a lot about them - but I do know that I can perform the create operation when using the context directly (not through a Data Service). Does this indicate that implementing the IUpdatable/IDataServiceUpdateProvider interface is indeed the answer? Do I implement this in the Service, in the entity classes, or on the client side (i.e - is there some documentation I can use)?

    Quite a lot to learn in WCF Data Services - I appreciate your advice.

    Thanks!

     


    Web: http://invoc.net Blog: http://invoc.net/CRM_BPOS_Blog
    Saturday, July 31, 2010 1:54 PM
  • Hi,

    I assume you implemented a so called context class (the one you pass as the generic parameter to DataService<T>) and on it you have your entity sets exposed as properties of type IQueryable<T>. That would mean you're using so called "reflection" provider.

    I don't have a handy implementation of IUpdatable for reflection provider, but the one described here should be very similar: http://blogs.msdn.com/b/alexj/archive/2010/02/11/creating-a-data-service-provider-part-7-update.aspx

    You can also find a sample implementation (similar to the one above) in the DSP Provider Toolkit here: http://www.odata.org/developers/odata-sdk

    Thanks,


    Vitek Karas [MSFT]
    Saturday, July 31, 2010 2:24 PM
    Moderator
  • Thanks Vitek - I'll give it a try!
    Web: http://invoc.net Blog: http://invoc.net/CRM_BPOS_Blog
    Monday, August 2, 2010 7:23 PM
  • Hi Vitek,

    I found out that the classes generated by the svcutil that I used do indeed implement IUpdatable (http://msdn.microsoft.com/en-us/library/ff681561.aspx - "Data Context Classes" section, 1st line). 

    As I mentioned before, I can perform updates via the SaveChanges() method when connected to the DataContext directly. My issue is when using a WCF Data Service that uses the DataContext as its data source. For some reason, I get the "Property Set Method Not Found" error there.

    Are there any other possibilities?

    Thanks,


    Web: http://invoc.net Blog: http://invoc.net/CRM_BPOS_Blog
    Monday, August 2, 2010 9:16 PM
  • Hi,

    Well it feels like a problem with the CRM classes. In any case, just by the exception message there's not much I can do. If you could provide the request you're trying to make and the full callstack of the exception, it would help. But I would probably go ask on the CRM forums instead as they will likely know more about this issue.

    Thanks,


    Vitek Karas [MSFT]
    Tuesday, August 3, 2010 8:18 AM
    Moderator
  • I think you're right, Vitek. These CRM tools are brand new - but I found one other person who's trying to do the same thing as myself, and he's having the same issue. Apparently, the crm (xrm) classes do not have the proper set methods for some of the entity properties.

    This other person is a better programmer than myself - this is what he said:

    "The Microsoft.Xrm.Client actually supports ASP.NET tracing; so if you turn that on you and go to the Trace Viewer; you will see what it is having a problem with.  The issue appears to be that the generated class does not have a "Set" method for the various "Label" fields (like statuscodelabel) and it tries to set it.

    I hacked up my xrm.cs file to have empty Set{}'s and that got past this issue; only to have it complain that OwerId had to be set (which the proxy marks as "ignore") - getting around that; leads to an "Object not set to a reference" error from CRM." http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/dca50354-28c7-4811-bc99-7b802cc2d3a2/

    If you have any advice on that front, please let me know, but I think it's a matter of the classes not being correctly generated by the svcutil tool to allow updates over a Data Service, even though they allow updates when not using a Data Service. I'll begin my research on that front now. Thank you so much for your help in understanding this issue.

    Best,

    Andy


    Web: http://invoc.net Blog: http://invoc.net/CRM_BPOS_Blog
    Tuesday, August 3, 2010 1:10 PM