无法获得JSONP与WCF数据服务工作数据、工作、JSONP、WCF

2023-09-03 16:18:25 作者:偏执怪人@

好像所有我阅读和观看,从WCF数据服务公开JSON应尽可能添加 JSONPSupportBehavior 属性服务类一样简单。

It seems from all that I read and watched, exposing JSON from a WCF Data Service should be as easy as adding the JSONPSupportBehavior attribute to the service class.

问题是,VS2010不承认 JSONPSupportBehavior 属性。

The problem is that VS2010 doesn't recognize the JSONPSupportBehavior attribute.

时有一个参考,我缺少什么?这似乎是所有的文章,它是支持开箱即用。

Is there a reference I am missing? It seems like from all the articles, it was supported out of the box.

推荐答案

WCF数据服务支持JSON开箱即用,无需添加属性或任何东西。

WCF Data Services supports JSON out of the box, no need to add attributes or anything.

在以收到的JSON响应格式客户端使用标准的HTTP内容类型协商。

In order to receive a response in JSON format clients use standard HTTP content type negotiation.

具体而言,他们需要包括应用程序/ JSON 请求的接受头。

Specifically, they need to include application/json in the accept header of the request.

有本节中的的OData协议文档的例子。

这些例子表明原始的HTTP请求。不同的客户端的HTTP的API有不同的机制来指定请求头。

These examples show the raw HTTP requests. Different client HTTP APIs have different mechanisms to specify request headers.

JSONPSupportBehavior 属性是一个扩展,它允许客户使用URL查询字符串选项的示例(即 $格式= JSON )除了内容类型协商,并且还增加了对JSONP(即 $回调= [函数名称]支持)。

The JSONPSupportBehavior attribute is an example of an extension that allows clients to use a URL query string option (i.e. $format=json) in addition to content-type negotiation, and also adds support for "JSONP" (i.e. $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.

如果你想使用 JSONPSupportBehavior 您可以在这里获得:

If you want to use the JSONPSupportBehavior you can obtain it here:

HTTP://$c$c.msdn.microsoft.com/DataServicesJSONP

 
精彩推荐
图片推荐