Friday, 26 December 2014

Include Header in Soap Request using CORS



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 = "http://ift.tt/1CLzqQb";

var soapRequest = '<?xml version="1.0" encoding="utf-8"?>' +
'<soap:Envelope xmlns:xsi="http://ift.tt/ra1lAU" xmlns:xsd="http://ift.tt/tphNwY" xmlns:soap="http://ift.tt/sVJIaE">' +
'<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 http://ift.tt/1CLzqQb. 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??


No comments:

Post a Comment