Wednesday, 6 September 2017

Calling SOAP Web Service from HANA XSJS

I am writing this blog to share my experience and code snippets for calling a SOAP Web Service from XSJS, creating a XML input (based on input parameters) and understanding the XML response to build a JSON output of your XSJS service.

Firstly, the xshttpdest file should be in the same folder, as your XSJS file (which has code calling the SOAP Web Service, in our case). It is not just the main package, but also the same folder/sub package.


Initially, we were not able to access the web service, from our HANA server. This is because of the Proxy settings on the HANA server. Network team has disable the proxy settings in HANA server, it is in DEV server. They might suggest to use a proxy for PROD server.

All the other configurations are the same, except creating a XML input and analyzing the XML response.

I wanted to share the code snippets, which might look repetitive. To make the blog complete with all the required code, for new users as well.

Let us see how the SOAP web service, call will look like. Import the WSDL, open it with tools like SOAP UI, which can help us to test the service. The SOAP service, will look like this: Use the host, port and the path as seen here.

SAP HANA Certifications, SAP HANA Materials, SAP HANA Tutorials, SAP HANA Learning, SAP HANA
Xshttpdest file configurations:

SAP HANA Certifications, SAP HANA Materials, SAP HANA Tutorials, SAP HANA Learning, SAP HANA

XSJS Code to call the SOAP web service

SAP HANA Certifications, SAP HANA Materials, SAP HANA Tutorials, SAP HANA Learning, SAP HANA

We will now see, how to build the XML for SOAP Web service.

SAP HANA Certifications, SAP HANA Materials, SAP HANA Tutorials, SAP HANA Learning, SAP HANA

I have to follow this approach, creating the XML input as a string and replaced the string where I need to pass on the values from the input request.

Observe the output XML in the SOAP UI tool, understand the nodes which will give you the required values. In my case, I have to read values from a node if it satisfies a specific condition.

My XSJS code, will look like this:

SAP HANA Certifications, SAP HANA Materials, SAP HANA Tutorials, SAP HANA Learning, SAP HANA

SAP HANA Certifications, SAP HANA Materials, SAP HANA Tutorials, SAP HANA Learning, SAP HANA

SAP HANA Certifications, SAP HANA Materials, SAP HANA Tutorials, SAP HANA Learning, SAP HANA

The extra logic I have included here is – Trying to find the indexOf of the required node name, using a Boolean value, will find the values of the child nodes as well. Building a JSON array, with the response data. We can now use this to construct the actual XSJS response.