Search code examples
wcf-data-servicesdynamic-data

WCF Data Service and dynamic data structure


Perhaps my question has no sense but I'll try to expose my problem : I'd like to expose custom data (based on the reflection provider) via WCF Data Service.

This data is a result of complex requests and its structure can be very much variable. I cannot modelize it through 4 or 5 custom classes that I'd expose via a Dataservice.

For example I can have a result like [date,name,age,function] or [date,time,page,type], [Country,hits,roi] ...etc. It's not possible for me to generate all combinations of results in custom classes and expose them through WCF Data Service.

So, is it possible to expose a data which has a very variable structure? When I see what Azure Table can do, I think it is possible, but I can't figure out how it's working.


Solution

  • In OData in general, you can do this with open types. An entity type is declared as as open in the $metadata document of the service by setting the OpenType attribute to true like this:

    <EntityType Name="Customer" OpenType="true">
    ...
    </EntityType>
    

    Which means that instances of that entity type may have any number of undeclared properties added to them dynamically (in addition to any declared properties on the type).

    The WCF Data Services reflection provider, however, doesn't provide support for open types out of the box. In order to use open types with WCF Data Services, you'll need to implement a custom provider (i.e., provide implementations of the IDataServiceQueryProvider and IDataServiceMetadataProvider). For help in writing custom providers, I recommend Alex's blog series here.