tags:

views:

46

answers:

2

I'm currently experimenting with using WCF Data Services as a way to open up our product a bit more while at the same time being able to consume the data from AJAX. One thing that I noticed is that the JSON represention format has these __metada members sprinkled across the data, and in the OData documentation I found this (under Representing Entries):

An optional "__metadata" name/value pair is the only pair that should be included on the object that does not directly represent a Property of the Entry being represented. This name/value pair is not data, but instead, by convention defined in this document, specifies the metadata for the Entry being represented.

My question is, if this metadata is optional, how do I turn it off to save bandwidth?

A: 

After spending some time in Reflector, it looks like the only way to do it is by writing my own version of System.Data.Services.Serializers.JsonSerializer. The method that writes the metada object, WriteMetadataObject, is called from WriteComplexTypeProperties and WriteElementWithName without considering any setting that would skip that portion.

Now I have to consider how much work it is to write a serializer that will write out the required JSON, and hook that into the pipeline with a custom $format name.

Dave Van den Eynde
+2  A: 

You are right that the WCF Data Services server implementation does not have the ability to not send the __metadata. The fact that the protocol makes it optional doesn't mean that a specific implementation won't send it always. In this case the server generates the __metadata because it may contain vital information for the client and without the the payload might not make sense or provide incomplete information. Currently the server also doesn't provide any option to change this behavior.

Vitek Karas MSFT
True, but the server could implement it in the form of a custom query option that is known to the client that doesn't need the metadata.
Dave Van den Eynde
You're right. You can add it as a suggested feature to our connect site. It will help us in planning the next releases.https://connect.microsoft.com/dataplatform/content/content.aspx?ContentID=15540
Vitek Karas MSFT