How to post soap request and parse xml result form a web service
I have to develop an application program for android with Titanium Studio 1.7.2.
To do this, I have to call a web service and parse the response. I tried this :
var url="https://minos.altran.com/minosweb/mnbzt_soap.php?action=MOBCONGEST_query";
var xhr = Titanium.Network.createHTTPClient();
var soapRequest = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<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:Header/>" +
"<soap:Body>" +
"<body xsi:type=\"data:query_params\" xmlns:data=\"http://minos.altran.com/MOBCONGEST/Data/\">" +
"<query_type>get_user_profil</query_type>" +
"<user xsi:type=\"data:user_profil\">" +
"<entite>"+metier+"</entite>" +
"<id_profil>"+id_p+"</id_profil>" +
"<login>"+field1.value+"</login>" +
"<password>"+field2.value+"</password>" +
"</user>" +
"</body>" +
"</soap:Body>"
"</soap:Envelope>";
xhr.open("GET", url);
xhr.send({username : "S-MINOS-BZT"});
xhr.send({password : "3knqt7ew!"});
xhr.setRequestHeader("WWW-Authenticate","Basic");
xhr.setRequestHeader("Content-Type","text/xml", "charset=utf-8");
xhr.setRequestHeader("Content-Length", soapRequest.length);
xhr.setRequestHeader("SOAPAction", "https://minos.altran.com/minosweb/classes/toolbox/minosgeneric/biztalk/soap/server/plugins/MOBCONGEST_query/wsdl/MOBCONGEST.wsdl");
xhr.onload = function() {
var doc = Titanium.XML.parseString(this.responseText);
var type = doc.getElementsByTagName("login");
Titanium.API.log(type.item(0).text);
};
xhr.send({xml : soapRequest});
But it still doesn’t work. What is wrong ?
2 Answers
-
Save yourself a lot of manual coding and try out Suds.js from Appcelerator's own Kevin Whinnery. I used it in the past successfully for .NET web services.
-
Thank you for your answer. I'm sure it was useful in the past but in suds.js I saw for example
xhr = new XMLHttpRequest();
which we can not use now.We have to usevar xhr = Titanium.Network.createHTTPClient();