on 01-24-2019 8:56 AM
Hi All,
I have to consume SOAP webservice in SAPUI5. I have try to call the soap webservice in SAPUI5 using Ajax, But I'm getting the following error.
Access to XMLHttpRequest at 'http://d0aavwboj01.hrpsdev.local:8080/DataServices/servlet/webservices?ver=2.1&label=job_rt_test&wsdlxml' from origin 'https://webidetesting7041551-cb8381de4.dispatcher.ap1.hana.ondemand.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Hi Venkatesh,
As I told in my answer, And also the SOAP service server should allow cross-domain calls. Actually, before sending the actual data request for cross-domain calls, clients send a pre-flight request first to the server to check whether the client is authorized to send cross-domain request to the server. i.e. preflight response should have header:
Access-Control-Allow-Origin: *
* means anyone can send a request, else your server domain should come here.
Thanks and Regards
Ashish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ashish,
The previous error is gone. Now, I'm getting the different error. Please check the screen shot and code. Please assist me.
onPressclk: function () {
var response = "";
var urldes = "http://";
var a ="http://"+"d0aavwboj01.hrpsdev.local:8000/DataServices/servlet/webservices?ver=2.1&label=job_rt_test&wsdlxml";
var request = '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:urn="urn:sap-com:document:sap:rfc:functions">'+
'<soap:Header/>' + '<soap:Body>' + '<inp:note>' + '<inp:to>RAMAKRISHNA</inp:to>' + '<inp:from>prabu</inp:from>' +
'<inp:heading>hello </inp:heading>' + '<inp:body>invoking real-time job via fiori</inp:body>' + '</inp:note>' + '</soap:Body>' +
'</soap:Envelope>';
$.ajax({
url: a,
type: "POST",
crossDomain: true,
data: request,
dataType: "xml",
processData: false,
contentType: "application/soap+xml; charset=utf-8",
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Credentials": false,
},
success: function (data, textStatus, jqXHR) {
response = data;
// console.log("Response : ", data);
},
error: function (xhr, status, thrownError) {
},
complete: function (xhr, status) {
// console.log("COMPLETE");
}
});
}
Hi,
There is nothing wrong with the way you are calling the SOAP service. You are getting CORS error, i.e. call to different server or from different client.
To overcome this, you need to set "crossDomain:true" in your ajax call. And also the SOAP service server should allow cross-domain calls. Then only you will be able to fetch the data.
If you are hosting UI5 application on SCP, you can create a destination pointing to SOAP service and call that destination directly from UI5 code. you won't get CORS error.
To read more about CORS issue please have a look at https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS.
Hope it helps 🙂
Thanks and Regards
Ashish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ashish Anand,
I have set "crossDomain:true" in my ajax call. But still I'm getting the error. I have mention the code below.
Can you please suggest me.
onPressclk:function()
{
var response = "";
var request = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:inp="http://businessobjects.com/service/Job_RT_Test/input">'
+'<soapenv:Header/>'
+'<soapenv:Body>'
+'<inp:note>'
+'<inp:to>RAMAKRISHNA</inp:to>'
+'<inp:from>prabu</inp:from>'
+'<inp:heading>hello </inp:heading>'
+'<inp:body>invoking real-time job via fiori</inp:body>'
+'</inp:note>'
+'</soapenv:Body>'
+'</soapenv:Envelope>';
$.ajax({
url:"http://d0aavwboj01.hrpsdev.local:8080/DataServices/servlet/webservices?ver=2.1&label=job_rt_test&wsdlxml",
// url:"/zzregutservice1",
type : "POST",
crossDomain:true,
data:request,
processData: false,
contentType: "application/soap+xml; charset=\"utf-8\"",
success : function(data, textStatus, jqXHR) {
response = data;
console.log("Response : ",data);
},
error: function(xhr, status, thrownError)
{
console.log("ERROR");
console.log("xhr : ",xhr);
console.log("status : ",status);
console.log("thrownError : ",thrownError);
},
complete: function(xhr,status)
{
console.log("COMPLETE");
}
});
}
User | Count |
---|---|
92 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.