Solved Access-Control-Allow-Origin Error in WCF REST Service


Recently I was working on a JSON based WCF REST Service. It was a simple service performing CRUD operation. When I tried to consume service from a web based client, got following errors in browser console.


Error message was, No Access-Control-Allow-Origin header is present on the required resource. Since service was running on different server and it was not configured to accept request from any origin. This error can be resolved by enabling CORS: Cross Origin Resource Sharing for the service.


You can enable CORS on service hosted on IIS or IIS Express by adding following configuration in config file.


We have added a custom header that allow Access-Control-Allow-Origin value to *. By setting it * , we are allowing request from any origin to access the service. So to solve error I went ahead and added following configuration in web.config of service under system.webServer section,

        <add name="Access-Control-Allow-Origin" value="*" />
    <modules runAllManagedModulesForAllRequests="true"/>  
    <directoryBrowse enabled="true"/>


After adding above configuration you should able to access service in client side codes like JavaScript. I hope this post is useful.

One thought on “Solved Access-Control-Allow-Origin Error in WCF REST Service

  1. Pingback: Dew Drop – June 12, 2014 (#1796) | Morning Dew

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s