Skip to Content
0

call SOAP XML webservice using xsjs and xshttpdest

Oct 19, 2017 at 02:53 PM

194

avatar image
Former Member

Hello All,

I need an urgent help on calling external service using xsjs.

I am getting an error "Error: HttpClient.request: request failed: internal error occurred \"Failed to send request to socket...rc = -1\"".

I have read many blogs regarding this error and tried to replicate the same but still I am getting this error.

My scenario is like I need to call an SOAP webservice by passing username and password. If its authenticated successfully, the SOAP service will trigger an Email.

Also I have uploaded the required certificate on XS trust connection.

Please find my below code:

XSJS:

try {
    var soapenv = 
'<?xml version="1.0" encoding="utf-8"?>'+
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:cxf="http://cxf.component.camel.apache.org/" xmlns:web="http://webservices.dsod.sap.com/">'+
'<soapenv:Header/>'+
'<soapenv:Body>'+
' <cxf:invoke>'+
' </cxf:invoke>'+
' <web:logonRequest>'+
'   <userName>ABC</userName>'+
'   <password>XYZ</password>'+
' </web:logonRequest>'+
'</soapenv:Body>'+
'</soapenv:Envelope>';
    
	var dest = $.net.http.readDestination("com.system.test", "external");
	var client = new $.net.http.Client();
	var req = new $.web.WebRequest($.net.http.POST,"");
	req.contentType = "text/xml";
	req.setBody(soapenv);
	client.request(req, dest);
	var response = client.getResponse();
	$.response.contentType = "application/json";
    $.response.setBody(response);
}
catch (e) {
    // return the error as JSON for debugging
     var errorResponse = {"error": e.toString()};
     $.response.status = $.net.http.INTERNAL_SERVER_ERROR;
     $.response.contentType = "application/json";
     $.response.setBody(JSON.stringify(errorResponse));
}

Can anyone please help me to figure out what I am actually missing here.

Regards,

Vicky

xshttpdest.png (7.8 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Sergio Guerrero Oct 25, 2017 at 10:11 PM
0
Share
10 |10000 characters needed characters left characters exceeded