1.) Невозможно выполнить запрос CORS от клиента к службе WCF.
2.) Как настроить WCF для разрешения запроса CORS от определенных доменов?.
Я пытался использовать некоторые настройки конфигурации, такие как
crossDomainScriptAccessEnabled
customHeaders
но в web.config все равно выдает ошибку CORS.
Помогите мне настроить доступ к конкретным запросам на основе их доменного имени или IP-адреса.
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="crossDomain" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="EndPointBehaviour">
<webHttp/>
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="MyNameSpace.MyService" behaviorConfiguration="ServiceBehaviour">
<endpoint
address="" behaviorConfiguration="EndPointBehaviour"
binding="webHttpBinding"
contract="MyNameSpace.IMyService" bindingConfiguration="crossDomain" />
</service>
</services>
<protocolMapping>
<add binding="webHttpBinding" scheme="http" bindingConfiguration="crossDomain" />
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*"/>
<add name="Access-Control-Allow-Headers" value="Content-Type, Accept" />
<add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS" />
<add name="Access-Control-Max-Age" value="1728000" />
</customHeaders>
</httpProtocol>