无法让 JSONP 与 WCF 数据服务一起使用

发布于 2024-09-04 05:29:01 字数 175 浏览 2 评论 0原文

从我阅读和观看的所有内容看来,从 WCF 数据服务公开 JSON 应该像向服务类添加 JSONPSupportBehavior 属性一样简单。

问题是 VS2010 无法识别 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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风和你 2024-09-11 05:29:01

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

为了接收 JSON 格式的响应,客户端使用标准 HTTP 内容类型协商。

具体来说,他们需要在请求的 accept 标头中包含 application/json

OData 协议文档的本节中有一些示例。

这些示例显示原始 HTTP 请求。不同的客户端 HTTP API 有不同的机制来指定请求标头。

JSONPSupportBehavior 属性是一个扩展示例,除了内容类型协商之外,它还允许客户端使用 URL 查询字符串选项(即 $format=json),并且添加了对“JSONP”的支持(即 $callback=[function-name])。

这些在您无法控制标头的情况下非常有用,例如通过脚本标记进行跨域访问时。

如果您想使用 JSONPSupportBehavior,您可以在此处获取它:

http:// code.msdn.microsoft.com/DataServicesJSONP

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.

These 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 (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.

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

http://code.msdn.microsoft.com/DataServicesJSONP

淡淡的优雅 2024-09-11 05:29:01

较新版本的 WCF 数据服务默认支持 JSON,并且您必须

Accept: application/json;odata=verbose

在请求标头中包含 JSON。

Accept: application/json

已经不够了。更多信息 此处

Newer versions of WCF Data Services support JSON by default and you must have

Accept: application/json;odata=verbose

in the request header.

Accept: application/json

is no longer sufficient. More info here.

ㄟ。诗瑗 2024-09-11 05:29:01

WCF 不仅支持开箱即用的 JSON,如果您使用 WCF WebApi(预览版 6),它还支持开箱即用的 JSONP。使用 NuGet 进入 VS 2010。安装完成后,请查看此处了解更多信息。

WCF not only suppors JSON out-of-the-box, but it also supports JSONP out-of-the-box if you use WCF WebApi (preview 6). Get in VS 2010 with NuGet. Once you have it installed, look here for more information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文