Reputation: 364
I am using javascript Http adapter to get data via SOAP webservice. Here, I am using ionic with MFP8.0.
My adapter implementation file is,
function getFeed(method, data) {
var sr =
"<soapenv:Envelope " +
"xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " + "xmlns:len=\"targetNamespace HERE" >" +
"<soapenv:Header/>"+
"<soapenv:Body>" +
"<len:authentication>" +
"<method>"+method+"</method>"+ data +
"</authentication></soapenv:Body></soapenv:Envelope>";
var input = {
method : 'post',
returnedContentType : 'xml',
path : 'PATH HERE',
body: {
content: sr,
contentType: 'text/xml; charset=utf-8',
},
};
return MFP.Server.invokeHttp(input);
}
In client is,
var resourceRequest = new WLResourceRequest("adapters/http/getFeed", WLResourceRequest.GET);
var dataList={
username:data.uname,
password:data.pswd
};
resourceRequest.setQueryParameter("params", "['myMethod', 'dataList']");
resourceRequest.send().then(
function(response) {
alert('response '+JSON.stringify(response.responseText));
},
function(response) {
alert("HTTP Failure "+JSON.stringify(response));
}
);
I need to pass the JsonObject Dynamically, It's contains username and password. I am sending the object via parameters.
But, I am not able to get the data in xml back. Can anyone tell me How to use JSON Object in XML format.
Upvotes: 0
Views: 482
Reputation: 181
Given the example you provided, in the client code you have a variable named dataList which is an object that contains the username and the password. However when you pass the data to the WLResourceRequest you do not pass this object, but you pass a string 'dataList'.
If you want to pass an object instead of a string you can do it like this:
var dataList={
username:data.uname,
password:data.pswd
};
resourceRequest.setQueryParameter("params", "['myMethod', '" + JSON.stringify(dataList) + "']");
Now, when you call the adapter, the first argument will receive the string "myMethod" and the second will be an object. So you can access the username and password, for example like this:
function getFeed(method, data) {
var username = data.username;
var password = data.password;
. . .
Upvotes: 2