Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs soap library throws a typeError on Firefox, not in Chrome

Tags:

soap

angularjs

I'm using the soap service for AngularJS from Andrew McGivery

It works perfectly when called from Chrome but it returns a typeError on Firefox and IE11.

TypeError: e is null at angular.soap.js line 16

The code in question is as follows:

.factory("$soap",['$q',function($q){
    return {
        post: function(url, action, params){
            var deferred = $q.defer();

            //Create SOAPClientParameters
            var soapParams = new SOAPClientParameters();
            for(var param in params){
                soapParams.add(param, params[param]);
            }

            var soapCallback = function(e){
                //ERROR THROWN ON LINE BELOW
                if(e.constructor.toString().indexOf("function Error()") != -1){
                    deferred.reject("An error has occurred.");
                } else {
                    deferred.resolve(e);
                }
            }

            SOAPClient.invoke(url, action, soapParams, true, soapCallback);

            return deferred.promise;
        },
        setCredentials: function(username, password){
            SOAPClient.username = username;
            SOAPClient.password = password;
        }
    }
}]);

e in Chrome is the object returned by my webservice (user object), in Firefox it's null and I don't know where to look in the library to debug the problem.

UPDATE:

My controller looks like this:

.controller('SoapCtrl', function($soap) {

    this.login = function(credentials) {

        $soap.post('MYAPI', 'MYMETHOD', {login: credentials.login, password: credentials.password}).then(function(data) {
            console.log(data.userid);
        });
    }

})

I also tried calling the same webservice from the jquery plugin jquery.soap inside my angular application and I get the expected behaviour in both Chrome and Firefox.

LAST UPDATE

Since this is a professional project, we decided to move on to a plugin that works. jquery.soap

2 issues have been posted on the author's page with no answer for the moment.

I would have awarded the bounty to a valid answer but half the bounty is going automatically to the answer with 2 upvotes...

like image 272
gyc Avatar asked Dec 08 '15 11:12

gyc


2 Answers

On the library, check the file soapclient.js, on the line 195

SOAPClient._onSendSoapRequest = function(method, async, callback, wsdl, req) 
{
    var o = null;
    var nd = SOAPClient._getElementsByTagName(req.responseXML, method + "Result");
    if(nd.length == 0)
        nd = SOAPClient._getElementsByTagName(req.responseXML, "return");   // PHP web Service?
    if(nd.length == 0)
    {
        if(req.responseXML.getElementsByTagName("faultcode").length > 0)
        {
            if(async || callback)
                o = new Error(500, req.responseXML.getElementsByTagName("faultstring")[0].childNodes[0].nodeValue);
            else
                throw new Error(500, req.responseXML.getElementsByTagName("faultstring")[0].childNodes[0].nodeValue);           
        }
    }
    else
        o = SOAPClient._soapresult2object(nd[0], wsdl);
    if(callback)
        callback(o, req.responseXML);
    if(!async)
        return o;
}

if you say that in firefox the e value it's null it's because in this method the o variable never it's set. Debug this method will be a help.

like image 167
Gonzalo Pincheira Arancibia Avatar answered Oct 21 '22 12:10

Gonzalo Pincheira Arancibia


in the function SOAPClient._getElementsByTagName
I change the line
return document.getElementsByTagName(tagName);
For
return document.getElementsByTagNameNS("*", tagName);

work for me!

like image 24
Celso Augusto Klingel Avatar answered Oct 21 '22 11:10

Celso Augusto Klingel