How To Consume Web Services With Sencha Touch

It’s possibile to consume a web service with Sencha Touch? Yes, with the Ajax.request service. Sencha Touch seem to have no tools to easily consume a web service, creating a soap envelope and getting back the XML response. But there is a way to send that envelope (manually created) with Ajax.request. Here an example of code created today by a colleague dealing with this problem.

The URLs are only example, in our case we were calling a web service exposed from Windows IIS Server.

   url: '',
   callbackKey: 'callback',
   scope: 'this',
   method: 'POST',
   headers: {'Content-Type': 'application/soap+xml; charset=utf-8; action=""'},
   success: function(response) {
      // OK
   failure: function(response) {
      // KO
   xmlData: '<?xml version="1.0" encoding="utf-8"?>\n<soap:Envelope xmlns:soap="" xmlns:csp=""><soap:Header/><soap:Body><csp:iphonenews><csp:lang>ita</csp:lang></csp:iphonenews></soap:Body></soap:Envelope>'

Note the call is SOAP 1.2 with the action passed on Content-Type header (you can alternatively use the SOAPAction header) and  the xmlData key which contain the full envelope (don’t miss the \n after the XML version declaration or remove it, many times it is not required).

The response is an XMLHttpRequest, contains the XML and you can get it with response.responseText or response.responseXML.

What to say… good luck!



2 replies on “How To Consume Web Services With Sencha Touch”

Leave a Reply