0

I found a similar post here but I am still not able to get to the solution to fix the issue I am facing.

Here's the jquery snippet of my soap request.

<script type="text/javascript">
    var invocation;
    $(document).ready(function () {

        invocation = new XMLHttpRequest();

        var webserUrl = "https://sc.quikstor.com/eComm3ServiceSS/QuikStorWebServiceSS.asmx/SmartPhone_Download_TenantInformation";

        var soapRequest = '<?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>' +
                            ' <SmartPhone_Download_TenantInformation xmlns="http://tempuri.org/">' +
                            '<csUser>someuser</csUser>' +
                            '<csPassword>userpassword</csPassword>' +
                            '<csSiteName>someString</csSiteName>' +
                            '<sSearchBy>someString</sSearchBy>' +
                            '</SmartPhone_Download_TenantInformation>' +
                            '</soap:Body>' +
                            '</soap:Envelope>';

        if (invocation) {
            invocation.open('POST', webserUrl, true);
            invocation.setRequestHeader('X-PINGOTHER', 'GetTenant');
            invocation.setRequestHeader('Content-Type', 'text/xml');
            invocation.onreadystatechange = function (data) { handleStateChange(data) };
            invocation.send(soapRequest);
        }
    });

    function handleStateChange(data) {
        switch (invocation.readyState) {
            case 0: // UNINITIALIZED
            case 1: // LOADING
            case 2: // LOADED
            case 3: // INTERACTIVE
                break;
            case 4: // COMPLETED
                //alert(data);
                break;
            default: alert("error");
        }
    }
</script>

It gives me following error on console:

XMLHttpRequest cannot load https://sc.quikstor.com/eComm3ServiceSS/QuikStorWebServiceSS.asmx/?op=SmartPhone_Download_TenantInformation. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:50099' is therefore not allowed access.

I have defined the header in soapRequest but it still gives me this error. I can't find a solution to this. Any suggestions??

Community
  • 1
  • 1
vohrahul
  • 1,123
  • 10
  • 17
  • Where's the jQuery at ? – adeneo Dec 26 '14 at 12:40
  • And BTW, if the server you're contacting doesn't allow cross origin resource sharing, there's no header you can set in your clientside script that solves it. – adeneo Dec 26 '14 at 12:41
  • the server I am contacting allows cross origin resource sharing. I am using CORS to send the soap request to the desired service. – vohrahul Dec 26 '14 at 12:42
  • I am very much new to the soap requests and CORS. I need to use some web services from here (https://sc.quikstor.com/eComm3ServiceSS/QuikStorWebServiceSS.asmx). And I have the desired credentials to use the web services there. – vohrahul Dec 26 '14 at 12:45
  • Well, you're clearly being pulled over by the same-origin policy, and when I visit the url (which seems to be wrong in your code, I'm guessing it's [**this**](https://sc.quikstor.com/eComm3ServiceSS/QuikStorWebServiceSS.asmx?op=SmartPhone_Download_TenantInformation)), there are no CORS headers present. – adeneo Dec 26 '14 at 12:52
  • Then how do I make a call to this web service if i have user, password and sitename? Can you edit the code and explain me the mistake I was making? I would be really grateful to you! – vohrahul Dec 26 '14 at 13:11
  • @vohrahul — You either change the service you are making the request to or you don't try to access it from client side JavaScript. – Quentin Dec 26 '14 at 13:20
  • @Quentin, thanks for the reply. So, if I make request from a server side language, it should work? – vohrahul Dec 26 '14 at 13:27
  • Yes. Doing it with server side code doesn't involve a third party, so the Same Origin Policy does not apply. – Quentin Dec 26 '14 at 13:28
  • ah! okay, thanks! I will try with c# now! – vohrahul Dec 26 '14 at 13:51

0 Answers0