如何避免跨域策略在jquery ajax消费wcf服务? [英] how to avoid cross domain policy in jquery ajax for consuming wcf service?

查看:131
本文介绍了如何避免跨域策略在jquery ajax消费wcf服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何避免在jquery ajax中使用wcf服务的跨域策略?

how to avoid cross domain policy in jquery ajax for consuming wcf service??

在跨域策略的web.config中我需要做什么chages? / p>

What chages do i need to do in web.config for cross domain policy?

推荐答案

如果你想从javascript到WCF的跨域调用,你必须使用JSONP。要向WCF添加JSONP支持,必须在 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆