views:

322

answers:

2

What am I missing here? It seems from all that I read and watched, exposing JSON from a WCF Data Service should be as easy as adding the '[JSONPSupportBehavior]' directive in front of the Service Class. Problem is VS2010 doesn't recognize 'JSONPSupportBehavior'. Is there a reference I am missing? Seemed like, from alll the articles, it was supportted outta the box.

TIA

S.

A: 

I don't think that it's included by default yet. See this link for some example code.

mdm20
+3  A: 

WCF Data Services supports JSON out of the box, no need to add attributes or anything. In order to receive a response in JSON format clients use standard HTTP content type negotiation. Specifically, they need to include "application/json" in the "accept" header of the request. There are examples in this section of the OData protocol documentation: http://www.odata.org/developers/protocols/operations#RetrievingfeedsEntriesandservicedocument

(those examples show the raw HTTP requests. different client HTTP APIs have different mechanisms to specify request headers)

The [JSONPSupportBehavior] attribute is an example of an extension that allows clients to use a URL query string option ($format=json) in addition to content-type negotiation, and also adds support for "JSONP" ($callback=[function-name]). These are useful in situations where you don't control the headers, such as when doing cross-domain access through script tags.

If you want to use the JSONPSupportBehavior you can obtain it here: http://code.msdn.microsoft.com/DataServicesJSONP

Pablo Castro
YEs, I had been to the link you supplied but missed the download link which had the class file in it. Thanks
SevilNatas