0

Error CORS appear when other domain request to wcf Restful. Here my App.config in window services. I just follow some code create wcf resful host in window service in this link

https://www.codeproject.com/Tips/1009004/WCF-RESTful-on-Windows-Service-Host?msg=5941830#xx5941830xx

App.config code :-

    <?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
    </startup>

    <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="RestWCFServiceLibrary.Service1Behavior">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
      
      <endpointBehaviors>
        <behavior name="web">
          <webHttp  />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    
    
    <services>
      <service behaviorConfiguration="RestWCFServiceLibrary.Service1Behavior"
               name="RestWCFServiceLibrary.RestWCFServiceLibrary">
        <endpoint address="" 
                  binding="webHttpBinding" 
                  contract="RestWCFServiceLibrary.IRestWCFServiceLibrary" 
                  behaviorConfiguration="web">
        </endpoint>
        <endpoint address="mex" 
                  binding="mexHttpBinding" 
                  contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8888/RestWCFServiceLibrary/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
      </customHeaders>
    </httpProtocol>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true"/>
  </system.webServer>
  </configuration>

but still fail to solve error CORS. Any idea to help me?

Access to fetch at 'http://localhost:8888/RestWCFServiceLibrary/json' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Wan Aideed
  • 41
  • 1
  • 6

0 Answers0