I’m trying to call asp.net webservice in javascript / Jquery,
i have tried so many examples but unfortunately not succeeded,
here is the code which currently i’m trying,
login("abc@gmail.com", "123456");
var productServiceUrl = 'http://localhost:50575/Service1.asmx?op=test'; // Preferably write this out from server side
function login(Email, Password) {
var soapMessage = '<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> \
<login xmlns="http://test.com/"> \
<Email>' + Email + '</Email> \
<Password>' + Password + '</Password> \
</login> \
</soap:Body> \
</soap:Envelope>';
$.ajax({
url: productServiceUrl,
type: "GET",
dataType: "xml",
data: soapMessage,
complete: endSaveProduct,
error: function (a, b, c) {
alert(a + "\n" + b + "\n" + c);
},
contentType: "text/xml; charset=\"utf-8\""
});
return false;
}
function endSaveProduct(xmlHttpRequest, status) {
$(xmlHttpRequest.responseXML)
.find('loginResult')
.each(function () {
alert( $(this).find('Message').text());
});
}
please help me out,
Thanks in advance.
There are multiple issues:
Access-Control-Allow-Origin: *or specifically allowing your originGETwhere as you should be usingPOST, because in SOAP over HTTP the envelope must be in the request body.jQuery always thinks your data isActually this is not true if theapplication/x-www-form-urlencodedunless you setprocessDatato false. Only settingcontentTypewill just make the header lie and doesn’t actually change this.dataparameter is a string.It appears that your target domain is not allowing CORS, so it is impossible to do it directly from client-side. You must use a server proxy to do the request.
If they allowed CORS, you would do it like so:
But this will not work because the server does not allow OPTIONS, which the browser must use to determine whether a cross-origin request is allowed:
The second problem is: