none
How to create a WCF rest service and consume it using CORS request RRS feed

  • Question

  • HI All,

    I have create a wcf rest service . I am trying to consume the same through an ajax request using CORS as the request mechanism.

    I am able to perform the following operations on the serice

    IN IE : 

    GET,POST,PUT,DELETE

    In chrome,firefox

    Only GET.

    For other requests, it give method not allowed(405 error).

    For POST , PUT preflighted request goes and the server rejects it.

    Can anyone tell how to acheive all http verb operations in all browser in CORS request

    Tuesday, April 1, 2014 5:09 AM

Answers

  • HI All,

    I am able to create a CORS based REST WCf service and consume it in a javascript client application.

    Just needed a bit of change in the code 

    • Marked as answer by Sushant Kadam Monday, April 7, 2014 3:58 AM
    Monday, April 7, 2014 3:57 AM

All replies

  • Hi,

    Enabling CORS for non-GET requests requires more than just setting the Access-Control-Allow-Origin header - it also needs to deal with preflight requests, which are OPTIONS requests which ask the server whether it's safe to perform operations which can potentially change data (e.g., POST, PUT, DELETE) before the actual request is sent.

    The following blog post about adding CORS support for WCF. It's not the simplest of the implementations, but hopefully the code in the post can be simply copied / pasted into your project. The post can be found at:
    #Implementing CORS support in WCF:
    http://blogs.msdn.com/b/carlosfigueira/archive/2012/05/15/implementing-cors-support-in-wcf.aspx .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, April 2, 2014 3:14 AM
    Moderator
  • HI

    Thanx for your reply . I agree the post is not simple.It is completely different from the posts i have seen,

    CORS works properly for IE but chrome and firefox has issues...

    Can anyone suggest a simple approach for the same ????????????

    Is there any way i can attach a sample project here ? Or send it to people ??????

    Regards,

    Sushant Kadam

    Thursday, April 3, 2014 4:16 AM
  • HI All,

    I am able to create a CORS based REST WCf service and consume it in a javascript client application.

    Just needed a bit of change in the code 

    • Marked as answer by Sushant Kadam Monday, April 7, 2014 3:58 AM
    Monday, April 7, 2014 3:57 AM