How to make WCF Dataservice stop tracking entity changes?

I have a web application that calls OData Webservice ( DataServiceContext ) through a proxy. The problem is that the code, although it makes an OData web service call each time, always returns old data after changing the content in the content management system (SDL Tridion).

 string getPageContentForUrl(string url) { var page = cdService .Pages .Expand("PageContent") .Where(x => x.Url == url) .FirstOrDefault(); if (page == null || page.PageContent == null) { return string.Empty; } else { return page.PageContent.Content; } } 

We needed to reset the application to see the latest data changes.

So, when debugging more, I noticed that

 var context = (System.Data.Services.Client.DataServiceContext)cdService; context.Entities[0].State = Unchanged 

so I tried setting it by calling .Detach() explicitly before returning the value from getPageContentForUrl , so something like

 cdService.Detach(page); cdService.Detach(page.PageContent); 

My question is: can I do the above on a more “global” level, maybe the webservice always takes the state as “Changed”, since I don’t want to manually write code in Detach() ?

+8
odata wcf-data-services tridion tridion-content-delivery
source share
2 answers

I think the answer is really - as you suspected - in the proxy server you are using, or rather in the DataServiceContext. This is what Microsoft has to say:

By default, the client only materializes the entry in the response feed into the object for objects that are not yet tracked by the DataServiceContext. This means that changes to objects are not already overwritten in the cache. This behavior is controlled by specifying a MergeOption value for queries and load operations.

For me, this sounds exactly like the behavior you are describing. Fortunately, caching can be disabled by setting the MergeOption property in the DataServiceContext.

See http://msdn.microsoft.com/en-us/library/gg602811.aspx .

+9
source share

As Quirijn already noted, it looks like the Tridion content delivery OData service returns caching results in your setup. Disconnecting and reconnecting the client is a tough job.

The Tridion content delivery object cache (if configured correctly) automatically removes items from its cache when they are updated by publishing actions from the content management system. Since this does not happen in your setup, it seems likely that your object cache is not configured correctly.

The easiest step is to find the cd_storage_conf.xml file of your cd_webservice web application and disable object caching (as Quirijn already said):

 <ObjectCache Enable="false" /> 

Now reinstall the application pool as you did before, and check again. If OData calls now always return updated content, your problem is really caused by a misconfigured object cache.

Unfortunately, at this point, all you do is disable the object cache, which will undoubtedly reduce the load the web service can handle. The next step should be to fix the configuration problem of your object cache.

To do this, I suggest contacting the SDL Professional Service or one of the SDL partners. Although setting up the object cache is not too complicated, it is too difficult to explain in Q & A.

+5
source share

All Articles