Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Invoke a Web Service with Jaggery (with Payload)

DZone's Guide to

Invoke a Web Service with Jaggery (with Payload)

· Web Dev Zone
Free Resource

Learn how to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

A few days go I wrote a post on how to call web services from jaggery (JavaScript mode). But in that article we call for web services where there is no payload. It requires just one parameter to be added but lot of people have asked about it, so I'm writing a post about this as well.

I will be using https://localhost:9443/admin/services/AuthenticationAdmin?wsdl and the login action.

To get the payload for jaggery WS, just get WS body and exclude the body tag, then add a name space on the call root.

eg:

var payload = '<aut:login mlns:aut="http://authentication.services.core.carbon.wso2.org">

<aut:username>admin</aut:username>

<aut:password>admin</aut:password>

<aut:remoteAddress>localhost</aut:remoteAddress>

</aut:login>';

Here is full jaggery code this fill print true or false depending on your server login username or password

<%

function invokeWebServices() {

var ws = require("ws");
var version = new ws.WSRequest();
var options = new Array();
options.useSOAP = 1.2;
options.action = "urn:login";
var usrName = "admin";
var pass = "admin";

var payload = '<aut:login xmlns:aut="http://authentication.services.core.carbon.wso2.org"><aut:username>' + usrName + '</aut:username><aut:password>' + pass + '</aut:password><aut:remoteAddress>localhost</aut:remoteAddress></aut:login>';

var result;

try {

version.open(options,"https://localhost:9443/admin/services/AuthenticationAdmin", false);
version.send(payload);
result = version.responseE4X;

} catch (e) {

log.error(e.toString());
return e.toString();

}

return result;

}

print(invokeWebServices());

%>




Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.

Topics:

Published at DZone with permission of Madhuka Udantha, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}