0

I have an old asp.net soap service that I need to keep running for the next few years but I am updating the interface to run via a webapp instead of an old Windows app.
I am trying to get to work and calling a simple method via jQuery AJAX (probably better ways to do it, sure).

I am running into CORS issues. I have access to the IIS server which the service is running. After checking all over the Googles AND reading suggestions on StackOverflow I implemented a few properties to the web.config to no avail.

I have tried setting the web.config settings:

        <add name="Access-Control-Allow-Origin" value="*" />
       <!-- <add name="Access-Control-Allow-Methods" value="*" />-->
        <add name="Access-Control-Allow-Methods" value="GET,POST,OPTIONS" />
        <add name="Access-Control-Allow-Headers" value="Content-Type, soapaction" />

So far my jQuery and HTML code is:

 <input type="text" value="" />
 <span>Push go</span>

<script src="https://code.jquery.com/jquery-3.7.1.min.js" crossorigin="anonymous"></script>
<script>
$('span').on('click', function(){
var number = $('input').val();
justGo(number);

});

//--RUNNING INTO CORS ISSUES
 function justGo(incomingNumber){
var SoaMessage = '<?xml version="1.0" encoding="utf-8"?>'
 +'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
 +'<soap:Body>'
 +'<IsUserCheckedIn xmlns="http://tempuri.org/">'
     + '<VisitorID>' + incomingNumber + '</VisitorID>'
    +'</IsUserCheckedIn>'
  +'</soap:Body>'
 +'</soap:Envelope>';
var url = "http://servicesite.somesite.com/ws/MyService.asmx?op=GetUserInfo";
//$.support.cors = true; //Even with this on it still same error
$.ajax({
 // crossorigin: "anonymous",
    type: "GET", //also POST
    url: url,
    //jsonpCallback: "GetUserInfo",  //Using SOAP so this doesn't work?
    dataType: "xml",
    processData: false,
    contentType: "text/xml; charset=\"utf-8\"",
    success: function (msg) {

   console.log("message: " + msg);
    },
    error: function (msg, xhr) {
        console.log("Failed: " + msg.status + ": " + msg.statusText);
    }

   });
   }
 </script>

I am running localhost via VisualStudio Code and Live Server. I also tried just tossing a index.html file up onto the same server as the service, AND a server that has the same domain (note that I am using port 80 right now for everything so it is not an HTTPS issue, and the service is only allowed internal to our networks, so it is not public and yes my local machine can resolve the service URL in my browser).

But so far nothing has helped me to hit the call and get a response back.
It just gets caught with the error:

Access to XMLHttpRequest at 'http://servicesite.somesite.com/ws/MyService.asmx?op=GetUserInfo' from origin 'http://MyCallingSite.somesite.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

OR

Access to XMLHttpRequest at 'http://servicesite.somesite.com/ws/MyService.asmx?op=GetUserInfo' from origin 'http://localhost:5501' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

Any ideas is super helpful?

I can ask ChatGPT, but that has given me mixed results in the past and most of the time the same answers I have found elsewhere.

UPDATE:

Current headers being passed in the network is:

enter image description here

9
  • First thing to do is check the browser "Network" developer tab and see what headers you're actually getting back from the server.
    – Pointy
    Commented Feb 6 at 1:31
  • Have you tried calling the service with the same data with something like postman or curl? Sometimes the browser will call CORS when it can't figure out the problem and it's actually something wrong with the server's response.
    – AJ W
    Commented Feb 6 at 1:31
  • Response to preflight means that your requests are triggering a CORS preflight, which your server most likely doesn't deal with correctly or at all - check the browser developer tools to see how your server is responding to OPTIONS requests - then read up on how CORS works Commented Feb 6 at 1:37
  • @Pointy, I updated my post with the request to the server and what I get back, it does look like it is responding with the headers, but no CORS allowance
    – ClosDesign
    Commented Feb 6 at 22:00
  • 1
    see how you get a 405 Method Not Allowed error for OPTIONS request - that's because your server doesn't handle CORS preflight at all (i.e. it rejects OPTIONS requests) - that's the first thing you need to fix - you can "open" CORS wide open, but if the http server doesn't allow OPTIONS requests, then a pre-flight will fail ... note: sending OPTIONS in Access-Control-Allow-Methods does NOT configure whatever http server you have to handle CORS preflight Commented Feb 6 at 22:05

0

Browse other questions tagged or ask your own question.