cancel
Showing results for 
Search instead for 
Did you mean: 

How to call SOAP web service from server side java script(XSJS) ?

sudhiranjan_lenka
Contributor
0 Kudos

Hi All,

I am struggling to call SOAP web service(RFC published as web service) from HANA.

I have created one "XXXX.xshttpdest" and one "XX.xsjs" as below.

XXXX.xshttpdest :-

host = "host name";

port = 8000;

description = "XXXX";

useSSL = false;

pathPrefix = "/PATH OF WS";

authType = none;

useProxy = false;

proxyHost = "";

proxyPort = 0;

timeout = 0;

XX.xsjs :-

try{

var dest = $.net.http.readDestination("PKG", "XXXX");

var client = new $.net.http.Client();

var req = new $.web.WebRequest($.net.http.GET,"?xType=YY");

var c = 0;

client.request(req, dest);

var  response= client.getResponse();

var body = '';

if (response.body) {

          body = response.body.asString();

          $.response.setBody( " body---> " + body);

}

else

          {

          $.response.setBody("Nothing from ERP,  and response status="+response.status);

          }

 

}

catch (e) {

          // TODO: handle exception

          $.response.setBody(" " error :--- "+e.message );

}

Note :-In Web service "xType" is mandatory and of string type.

Our web service is tested and it's working fine.

I am sure It's calling the web service but issue is with parameter passing and type of method I have used(GET).

O/p-- Nothing from ERP,  and response status=415(Means Unsupported media type).

Please help where I am wrong or any example to make the POST call to web service.I can construct SOAP Envelop only issue is how to pass it through XSJS.

Please help If any one already tried.

Thanks in advance.

Thanks,

Sudhir.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi, did you have any luck on this? Looking to do the same thing.

sudhiranjan_lenka
Contributor
0 Kudos

Hi Sebastian,

Please see below If this helps you but it worked for me.

var dest = $.net.http.readDestination("PKG", "XXXX");

var data='<?xml version="1.0" encoding="utf-8"?>'

+'<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>'

+'<n0:ZlhAlmNotifCreate xmlns:n0="urn:sap-com:document:sap:soap:functions:mc-style">'

......................................

+'</n0:ZlhAlmNotifCreate>'

+'</soap:Body>'

+'</soap:Envelope>';

var req = new $.web.WebRequest($.net.http.POST,"");

req.contentType = "text/xml";

req.setBody(data);

client.request(req, dest);

var  response= client.getResponse();

//same code as mentioned above

Please mark as correct answer If it works for you.

Thanks and Regards,

Sudhir.

Former Member
0 Kudos

will try that now. Thanks!

Former Member
0 Kudos

The connection works, but I'm having trouble passing credentials to the server using basic Auth. Have you tried that before?

Former Member
0 Kudos

Right now I'm exploring the XS Administration tool for this. Will keep you posted.

sudhiranjan_lenka
Contributor
0 Kudos

Thanks Sebastian.

Former Member
0 Kudos

For some reason, the basic auth credentials aren't getting saved in the admin tool when I click save in the destination.

I suspect it might be a security issue even though I have tested by granting all the *xs* roles to my user. The bar at the bottom says Destination Successfully saved but I can see there is a request that fails in my javascript console:

[12:15:24.895] POST http://<HOST>:80<SID>/sap/hana/xs/admin/logic/httpDestSecStore.xscfunc [HTTP/1.1 500 Internal Server Error 198ms]

Any ideas?

Also the tool is extremely slow. Just loading the page takes minutes!

vimadaan
Explorer
0 Kudos


I am facing the same issue as mentioned by you above. I am not able to save the user id and password in the HTTP Destination in the web portal. You are right it is very slow as well.

Please help if you are able to solve the save issue.

Former Member
0 Kudos

By any chance.. this issue got fixed.. even we are not able to save the basic authentication user id/password

Answers (0)