Bag/Collection support of V3 in V2 - Writing custom proxy generator

Topics: General, OData Library, WCF Data Services
Oct 3, 2012 at 1:24 PM

Hello All,

My query is again related with Bag/Collection support in OData.

Problem Statement: Server side implementation is in Java. We have implemented odata V2 but added feature of Collection (which is part of V3- Not sure if we should be doing this and .NET will accept it as published data service version will be 2 only) . Because of this, when I add reference to my service, default proxy generation tool reports error (DataSvcutil.exe). 

The 'Type' attribute is invalid - The value 'Collection(Edm.String)' is invalid according to its datatype '' - The value 'Collection(Edm.String)' is not valid according to any of the memberTypes of the union.

My question is, is it possible to write my own WCF Proxy generator so that I can generate my own reference.cs file.  If yes, how big the effort would be? Basically I would just like to make sure that when system encounters "Collection" in metadata or data, it will parse details and generate required proxy classes.

Also any public service example of V3 implementation or V2 where collection are implemented would be of great help.

My earlier post related with OData was:

Also please let me know if I am in completely wrong direction and what I am trying to do is not going to work.


Viral Thakkar

Oct 3, 2012 at 3:22 PM


In short I would strongly advice against having a service which only supports V2 but still exposes collection properties. As you already noted, it will break all existing clients (since they won't understand it). Is there a reason you only support V2? Why not make the service a V3 service? It's not like you're going to break clients which are not already broken by the presence of the collection property.

Writing your own code generator is definitely possible, and I would say it's somewhat costly, but not too much. You could start with the T4 template which should be easy to customize for your needs. But then again, making your service V3 will just fix this for your for free.

Currently we don't have a public service with collection properties, but it's very easy to spin it up using the reflection provider in .NET (just add a property of type IEnumerable<int> to an entity).



Oct 4, 2012 at 1:07 PM

Hi Vitek,

Thanks for your reply. 

Unfortunately publishing service as V3 is something we cannot do. We are using odata4j library of java for server side implementation which is yet to support V3. We have modified their library to add collection support on our own. 

So now my final query would be, is it possible to write custom code generator in such a way so that for all other areas, internal code (datasvcutil.exe) will kick in ( like for V2 features of service) to write proxies, only when we encounter collection feature, my code will kick in and write the required code for generating proxy - basically to override/add only collection proxy generator and do not touch existing code generation.

Also I am not sure but do we have access to code base of datasvcutil.exe - just a random query.

Also apart from collection(primitive type), we have implemented collection(Complextype) also. I hope we will be able to deal with that also. 

Again thanks for your help on this. 

Viral Thakkar

Oct 4, 2012 at 5:06 PM

First, just making sure, you are aware that by doing this you are not actually creating an OData service, just something which looks like one? No other client will be able to talk to your service...

I don't think there's a way to modify the existing datasvcutil to do what you want. I think using the T4 template would be a better option, as that should be easily modifiable.


Vitek Karas