torsdag den 26. marts 2015

How to make WCF service available for JavaScript from for foreign server

Normaly you could not make XMLHttpRequest in JavaScript to a service on another server.

If you have access to change the Web.Config on the server you want til make request to, you can set up some extra information for the http header to make request possibly.

Example - part of Web.Config file

<configuration>
......
   <system.webServer>
......  
    <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>
......  
   </system.webServer>
......  
</configuration>

You can find more information here:
Description in details:

Thank you Jeppe B for the solution.

Ingen kommentarer:

Send en kommentar