CORS in WCF REST Service – Easy WCF
Skip to content

CORS in WCF REST Service

In this article, we will learn:

  • What is CORS?
  • How CORS works?
  • How to solve cross origin request in WCF Rest


What is CORS?

Cross-origin resource sharing (CORS) is a mechanism that allows restricted resources (e.g. fonts) on a web page to be requested from another domain outside the domain from which the resource originated.

CORS defines a way in which a browser and server can interact to safely determine whether or not to allow the cross-origin request. It allows for more freedom and functionality than purely same-origin requests, but is more secure than simply allowing all cross-origin requests

How CORS works?

The CORS standard describes new HTTP headers which provide browsers and servers a way to request remote URLs only when they have permission. Although some validation and authorization can be performed by the server, it is generally the browser’s responsibility to support these headers and respect the restrictions they impose.

cross origin request

you can read more on CORS here.
CORS Origin

How to solve CORS issue in WCF Rest?

Let’s say you have a WCF rest service and you are trying to consume the service from a web client. You will get below error.

“No Access-Control-Allow-Origin header is present on the required resource”

If you are seeing this erro, that means the service is running on a different server and it is not configured to accept a request from any origin.

This error can be resolved by enabling CORS: Cross Origin Resource Sharing for the service.

After adding the configuration, you will able to access a service in client side code like JavaScript.

© 2015, admin. All rights reserved.

Leave a Reply

Your email address will not be published. Required fields are marked *