JavaScript SOAP Client and AngularJS

It is December 2007, The first Iphone has been around just for about 6 months, youtube launched its mobile site providing videos in 3gp. A lot of things have changed since then! This was the year when the Javascript SOAP client originally created by Matteo Casati was last updated. SOAP hasn’t changed much all these years, however the platforms have. Consuming webservices is now the core of Mobile applications and the integration between traditional client based applications and the cloud base services.

The first problem we have to overcome with this old Javascript library is offline error handling. Making requests from a browser assumes that you have internet access, on the other hand, mobile devices often have network issues due to a poor cellular data signal.

1. Catch an error if the server is unavailable, the url is incorrect or the client can’t load the wsdl:

We check for the state as well as the status on lines 16,17 and reject the request passing a null callback as well as the error text returned by the server.

2. The second issue is Timeouts, even in 2007 with half of the world still using a dial-up internet connection (laughs.mp3) it was very unlikely for your request not to come back after a decent time. On Mobile devices and the broadband we are used to these days, if it takes more than 30 seconds to get your response it is outrageous!

We set up the timeout on line 2 and create the xmlHttp.ontimeout function on line 8 that sends a null call back that can be handled by your application. I included the the error text passed by the timeout.type attribute so you know your request has timed out.

We all know maintaining code is not an easy task, but if someone wants to re-use it, why not fixing it?

These modifications were tested using PHP on Magento E-Commerce, as well as mobile applications using Ionic/AnuglarJS.

Source code:

Forked from andrewmcgivery/angular-soap

Leave a Reply