WCF OData Service with Reflection Provider

We need to provide an API for the activity feed (think about Facebook), and we decided to try OData. We use .NET, so we went to the WCF data service, but we don’t use the Entity Framework (or any other ORM), so we will use the Reflection provider. Since we have complex business logic for our search methods, we decided to expose them as official operations. However, we want to show the deletion / update and allocation of a single object as a regular OData REST resource. My question is how can we implement a data source for the reflection provider, which restricts access to collections, but allows access to single objects (with the requested key), allows the use of DELETE / PUT / POST commands, and also allows access to child collections of individual objects (i.e. service / Category (1) / Products). Basically I want to restrict access to basic sets (e.g. service / categories or service / products)

+6
odata wcf
source share
1 answer

There is no great answer here.

There are two settings you can use inside InitializeService (..)

config.SetEntitySetAccessRule("Feed", EntitySetRights.ReadSingle); config.SetEntitySetPageSize("Feed", 1); 

Unfortunately, you are not doing what you want:

  • EntitySetRights.ReadSingle restricts you to returning only one object from this set. What fails because it does not allow / Categories (1) / Products AND also allows / Categories? $ Filter = ... return a string.
  • SetEntitySetPageSize limits the amount of initial load that gets to the server to one record, but you can follow $ skiptoken to go and get the rest of the data one record at a time and in the same way as (1) it allows arbitrary requests and not only key predicates.

This leaves you with only one realistic option. Visit the LINQ expression and develop if you allow what is being done.

Since you use the Reflection provider, you basically need to wrap the IQueryables returned from your "context" class and look for invalid queries before passing them.

Not to lose consciousness.

If you decide to go this route, you will find a useful example of using IQueryable , and you should check the Viteks blog post series for data service expressions .

Hope this helps

Alex (OData Program Manager)

+5
source share

All Articles