locked
Listdata.svc - DataContext no longer valid when editing a SharePoint List RRS feed

  • Question

  • I have an external WCF Service that will consume SharePoint listdata.svc in order to add a new item to a SP List.

    The problem is that if I edit the SP List by removing or adding a new column, the DataContext willl not be valid because the item property does not contain the new column.

    var dataContext = new TestDataContext(new Uri("http://baba/teamsites/FI/_vti_bin/listdata.svc/"));
    dataContext.Credentials = CredentialCache.DefaultNetworkCredentials;
    TaskListItem taskItem = dataContext.TaskList.Where(i => i.Title == incidentNumber).FirstOrDefault();
    if (taskItem == null)
                {
                    taskItem = new TaskListItem();
                    taskItem.Title = incidentNumber;
                    taskItem.TaskType = Incident;
                    taskItem.WorkflowStatus = String.Empty;
                    dataContext.AddToTaskList(taskItem);
                }
    04/15/2013 08:30:46.71 	OWSTIMER.EXE (0x19E0)                   	0x1ED8	Unknown                       	TimerJob Action exception     	0000	High    	System.InvalidOperationException: The closed type RetrievingIncidentTimer.ListDataService.TaskListItem does not have a corresponding TaskManagementWorkflow settable property.     at System.Data.Services.Client.AtomMaterializer.MaterializeDataValues(ClientType actualType, List`1 values, Boolean ignoreMissingProperties, DataServiceContext context)     at System.Data.Services.Client.AtomMaterializer.MaterializeResolvedEntry(AtomEntry entry, Boolean includeLinks)     at System.Data.Services.Client.AtomMaterializerInvoker.DirectMaterializePlan(Object materializer, Object entry, Type expectedEntryType)     at System.Data.Services.Client.AtomMaterializer.Read()     at System.Data.Services.Client.MaterializeAtom.MoveNextInternal()     at System.Data.Services.Client.MaterializeAtom.MoveNext()     a...	f13e90fa-1d1e-42d8-9e88-fc0e36311529
    04/15/2013 08:30:46.71*	OWSTIMER.EXE (0x19E0)                   	0x1ED8	Unknown                       	TimerJob Action exception     	0000	High    	...t System.Linq.Enumerable.<CastIterator>d__aa`1.MoveNext()     at RetrievingIncidentTimer.RetrievingIncidentTimer.Execute(Guid targetInstanceId)	f13e90fa-1d1e-42d8-9e88-fc0e36311529

    To fix the problem, I have to refresh the service references to the Sharepoint Listdata service and deploy the new WCF Service each time there is an edit of the SharePoint List. Is there another solution to not refresh every time?





    • Edited by okdreamy Monday, April 15, 2013 7:24 AM
    Monday, April 15, 2013 7:12 AM

Answers

  • I think that has something to do with the WCF signature, it creates an XML structure for the list or something, and when you update/add a list item then the XML gets sent to the service and then there is a discrepancy between them...or something like that.

    One thing I did learn is that once you start developing services for lists then do not change the list structure, but if you do need to change the list structure then you need to update all services.

    Here is a post which explains it a lot better than I ever could :)
    http://stackoverflow.com/questions/4272478/adding-field-to-wcf-data-contract-breaks-clients

    Regards
    Pieter
    • Marked as answer by okdreamy Monday, April 15, 2013 12:57 PM
    Monday, April 15, 2013 11:12 AM

All replies

  • Hi,

    What you are currently doing is the fix for this.

    A way to workaround this, but also change your application completely is to create your own WCF service using the Server Object Model.
    Microsoft.SharePoint

    Regards
    Pieter
    Monday, April 15, 2013 8:51 AM
  • But in this case, does the WCF Service need to be hosted in the SharePoint site? The SharePoint site cannot be access from the outside network.

    And what about the Client Object Model?

    • Edited by okdreamy Monday, April 15, 2013 9:07 AM
    Monday, April 15, 2013 9:01 AM
  • Hi,

    The Client Object Model, when run without a SPMetal class would work.

    You have 2 choices, either host the WCF service in SharePoint or from another site in the same network. I would recommend running the service in SP, depending on load of course, seeing as the service and SharePoint would use the same worker process.

    Here is a good comparison between the 2 hosting options.
    http://nikspatel.wordpress.com/2012/02/29/deploying-custom-wcf-service-to-iis-vs-sharepoint/

    Below I also list an article on how to consume WCF service which is hosted in SharePoint,http://sharepoint.stackexchange.com/questions/53408/how-to-consume-custom-wcf-service-hosted-in-sharepoint-2010-from-outside-in-c


    Regards
    Pieter

    Monday, April 15, 2013 9:18 AM
  • PieterJvr> Yes I was thinking of hosting the serving in SharePoint. However the wcf service will be consumed from outside, but the SharePoint site can only be access from the intranet.

    I think I am going to use the Client Object Model instead of the Lists SharePoint Services. But why would they add different methods to edit SharePoint site (add or edit items...) and so on if you can rather just use the Client Object Model?

    Monday, April 15, 2013 10:59 AM
  • I think that has something to do with the WCF signature, it creates an XML structure for the list or something, and when you update/add a list item then the XML gets sent to the service and then there is a discrepancy between them...or something like that.

    One thing I did learn is that once you start developing services for lists then do not change the list structure, but if you do need to change the list structure then you need to update all services.

    Here is a post which explains it a lot better than I ever could :)
    http://stackoverflow.com/questions/4272478/adding-field-to-wcf-data-contract-breaks-clients

    Regards
    Pieter
    • Marked as answer by okdreamy Monday, April 15, 2013 12:57 PM
    Monday, April 15, 2013 11:12 AM
  • Hi,

    I have fixed this by setting the IgnoreMissingProperties property of the data context object to true.

    dataContext.IgnoreMissingProperties = true;

    Regards,

    Iurie

    Thursday, August 22, 2013 4:50 PM