cancel
Showing results for 
Search instead for 
Did you mean: 

How to consume SOAP webservices(XML) in SAP UI5 application

0 Kudos

How to consume SOAP webservices(XML) in SAP UI5 application using BAS environment ?

Margot
Product and Topic Expert
Product and Topic Expert
0 Kudos

Could you be a little more specific about what you mean and what you want to achieve?

junwu
Active Contributor
0 Kudos

do google please

Accepted Solutions (1)

Accepted Solutions (1)

leonikussmaul
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Parandhaman,

If you need to consume a SOAP Service in UI5, I would suggest making an ajax call.

Depending on the Payload needed for your API, it is likely best to modularize separate functions that build i.e. the SOAP Header, Item(s), Footer, etc. Inside each of these functions, you can simply wrap the XML tags in strings and concatenate them with dynamic variables that contain the data.

var sPayload =
'<soapenv:Header/>' +
'<soapenv:Body>' +
'<SoapItem>' + oSoapItem + '</SoapItem>' +
... ;

Once the sPayload is built, you would pass it to your ajax call along with some required headers such as contentType. I have also pointed towards a BTP destination in the below example, but this might differ based on your use case. You would need to define this in your xs-app.json and configure the destination in BTP accordingly.

postSoap: function(sPayload){
var that = this;
$.ajax({
url:"destination/yourApiUrl",
method: "POST",
data: sPayload,
Accept" "*/*",
contentType" "text/xml",
success: function(oSuccess){}.bind(this),
error: function(oError){},
});
}

I strongly suggest testing the API calls in Postman first and then taking the successful payload as a blueprint to recreate the same in your Ui5 app. Vice versa, you can copy the payload from your Ui5 app from the network tab and cross-check any issues via Postman. Good luck!

0 Kudos

Hi leonikussmaul,

Thanks for your reply.I tried the method you said, in Ui5 network tab and Postman am getting 200 status but am getting CORS error while fetching the values. Please help to solve the error.Thanks,Paran
leonikussmaul
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Paran,

Are you hitting the BTP destination successfully from the app? If not, this is to be expected. Due to same-origin policy, the browser would deny any ajax requests pointing to service endpoints with different domains. For this reason, you need to configure the BTP destination in the cockpit. Please check the SDK for the same BTP Destinations

If you have already done that, please check if your BTP destination is configured correctly and has all the required additional parameters, i.e. when you run "check connection" on your destination, what is the response you are getting?

0 Kudos

Hi Leoni,

I added destination required parameters in BTP it's showing 404 error but in post man it's showing 200 success.

Please help on this.

leonikussmaul
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Paran,

Based on your response, it is unclear to me whether you followed the steps described in my previous comment.

Anyways, it seems like your BTP destination is not being hit correctly. Postman is not using destinations so naturally, it would return 200 in this case.

Are you using managed or standalone approuter? What is the path referenced in your ajax call? Have you referenced the destination properly? You might need to use a relative path rather than absolute path to ensure the route defined in xs-app json is hit and calls the destination.

Without all this information, it will be difficult to help you. Again, strongly suggesting you refer to the above shared blog.

Answers (0)