cancel
Showing results for 
Search instead for 
Did you mean: 

How to call SOAP webservice in SAPUI5 ?

former_member198924
Participant
0 Kudos

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. 

Accepted Solutions (0)

Answers (2)

Answers (2)

AshishAnand
Employee
Employee
0 Kudos

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

former_member198924
Participant
0 Kudos

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");
				}
			});


		}

AshishAnand
Employee
Employee
0 Kudos

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

former_member198924
Participant
0 Kudos

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"); 


											     }


											}); 	
 
		}