Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

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

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.

Tags:
replied

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.

1 View this answer in context
Not what you were looking for? View more on this topic or Ask a question