如何避免在 jquery ajax 中使用跨域策略来使用 wcf 服务? [英] how to avoid cross domain policy in jquery ajax for consuming wcf service?
本文介绍了如何避免在 jquery ajax 中使用跨域策略来使用 wcf 服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何避免jquery ajax中使用wcf服务的跨域策略??
how to avoid cross domain policy in jquery ajax for consuming wcf service??
我需要在 web.config 中为跨域策略做哪些更改?
What chages do i need to do in web.config for cross domain policy?
推荐答案
如果您希望从 javascript 到 WCF 的跨域调用,您必须使用 JSONP.要将 JSONP 支持添加到 WCF,您必须在 WebHttpBinding
中定义它.配置应如下所示:
If you want cross domain calls from javascript to WCF you must use JSONP. To add JSONP support to WCF you must define it in WebHttpBinding
. The configuration should look like:
<bindings>
<webHttpBinding>
<binding name="crossDomain" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</binding>
<behaviors>
<endpointBehavior>
<behavior name="restBehavior">
<webHttp />
</behavior>
</endpointBehavior>
</behaviors>
<services>
<service name="...">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="crossDomain"
contract="..." behaviorConfigurations="restBehavior" />
</service>
</services>
对于 jQuery 部分检查例如 这篇文章.
For jQuery part check for example this article.
这篇关于如何避免在 jquery ajax 中使用跨域策略来使用 wcf 服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文