none
Consuming WebService through ajax post method getting Cross OrginError but through tool it is working fine.What is the difference between code and tool RRS feed

  • Question

  • This service  using Postman and Fiddler working fine but   using ajax code getting this error( Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.").Why code only getting this error but using postman why not getting error?What is the difference between code and tool?

    MohanV

    Tuesday, August 16, 2016 12:47 PM

Answers

  • Hi MohanV,

    Based on this error message, it seems you call WCF Rest Service in different domains, am I right? If so, I suggest you try to add below code in the service side of configuration file.

    <system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
      </customHeaders>
    </httpProtocol>
    </system.webServer>

    For another way, you could develop new behavior which adds “("Access-Control-Allow-Origin", "*")” to response header and include it in the endpoint configuration. You could refer the link below for more information.

    # CORS on WCF
    http://enable-cors.org/server_wcf.html

    Best Regards,

    Edward

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you.
    Microsoft does not control these sites and has not tested any software or information found on these sites;
    Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.
    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    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.


    Tuesday, August 16, 2016 11:17 AM
  • Hi MohanV,

    >> using ajax code getting this error( Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource

    Request in ajax and Fiddler are different. Modern browsers will only allow Ajax calls to services in the same domain. Do you want to call WCF Rest service from different domain? If so, have you tried my above suggestions? If it did not work, it would be helpful if you could share us more information about your service.

    Best Regards,

    Edward


    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, August 17, 2016 7:15 AM

All replies

  • Consuming the webservice i am getting the error as follows:

    XMLHttpRequest cannot load http://mdwaccess.com/DMSContextREST/rest/WYH/MRCCCCFStatus. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

    How to resolve this issue?For this resolution   what changes is requierd?Whether is it required client side or server side?

    Thanks,

    Mohan


    MohanV

    Monday, August 15, 2016 8:13 AM
  • Hi MohanV,

    Based on this error message, it seems you call WCF Rest Service in different domains, am I right? If so, I suggest you try to add below code in the service side of configuration file.

    <system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
      </customHeaders>
    </httpProtocol>
    </system.webServer>

    For another way, you could develop new behavior which adds “("Access-Control-Allow-Origin", "*")” to response header and include it in the endpoint configuration. You could refer the link below for more information.

    # CORS on WCF
    http://enable-cors.org/server_wcf.html

    Best Regards,

    Edward

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you.
    Microsoft does not control these sites and has not tested any software or information found on these sites;
    Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.
    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    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.


    Tuesday, August 16, 2016 11:17 AM
  • This service  using Postman and Fiddler working fine but   using ajax code getting this error( Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.").Why code only getting this error but using postman why not getting error?What is the difference between code and tool?

    MohanV

    Tuesday, August 16, 2016 12:30 PM
  • Hi MohanV,

    >> using ajax code getting this error( Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource

    Request in ajax and Fiddler are different. Modern browsers will only allow Ajax calls to services in the same domain. Do you want to call WCF Rest service from different domain? If so, have you tried my above suggestions? If it did not work, it would be helpful if you could share us more information about your service.

    Best Regards,

    Edward


    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, August 17, 2016 7:15 AM