wcf发布的服务在前端调用时,遇到跨域问题的解决方案

我是使用IIS作为服务的宿主,因此需要在web.config中增加如下配置节:

<bindings>
<webHttpBinding>
<binding name="webBinding" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>

然后在终点上应用绑定配置:

<endpoint address="" binding="webHttpBinding" bindingConfiguration="webBinding" contract="Jintu.Report.Interface.IReportService" behaviorConfiguration="webHttp"/>

除配置文件中增加配置信息外,还需要在接口实现类(服务)上增加如下属性:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[JavascriptCallbackBehavior(UrlParameterName ="jsoncallback")]

原文地址:https://www.cnblogs.com/SimpleGIS/p/6796179.html