1

im new in this field of IT and i'm doing an apprentienship, the goal of this appreintienship, is making an app that retrieve data from a server that runs SOAP (unfortunately), that's my first call for gettin' some Info about Owner inside the server. The call doesn't work (i wrote sh*t in my code for sure) and i don't know how to correct it and make a better SOAP call. Here's the code

var myApp = angular.module('myApp', []);
myApp.controller('myCtrl', function($scope,$http) {
    var sr = 
                '<?xml version="1.0" encoding="utf-8"?>' + 
                '<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>' +
                        '<AuthHeader xmlns="Logisense_EngageIP">' + 
                            '<Username>admin</Username>' + 
                            '<Password>admin</Password>' +
                        '</AuthHeader>' +
                    '</soap:Header>' +
                    '<soap:Body>' + 
                        '<GetOwnersUsers xmlns="Logisense_EngageIP">' + 
                            '<ownerUsername>string</ownerUsername>' + 
                        '</GetOwnersUsers>' +
                    '</soap:Body>' +
                '</soap:Envelope>';
    var soapResponse = null;
    function makeSoap(){
        $http.post('31.44.16.67/GetOwnersUsers', sr)
            .success(function(data) {
                soapResponse = data;
                $scope.response = soapResponse;
            });
    }
    $scope.callSoap = function(){
        $scope.soapRequest = sr;
        makeSoap();
    };
});

Thanks you all anticipately for tips and hints!

1 Answer 1

1

SOAP is the worst thing that can happen to a webapp.

For our apps we use the javascript SOAP client library.

In your angular app you need to create a module with a factory:

angular.module('angularSoap', []).factory("$soap", [ '$q', "$http", function($q, $http) {
    return {
        post : function(action, params) {
            var deferred = $q.defer();
            var soapParams = new SOAPClientParameters();
            for ( var param in params) {
                soapParams.add(param, params[param]);
            }
            var soapCallback = function(e) {
                if (e.constructor.toString().indexOf("function Error()") != -1) {
                    deferred.reject(e);
                } else {
                    deferred.resolve(e);
                }
            }
            SOAPClient.invoke('http://31.44.16.67/GetOwnersUsers', action, soapParams, true, soapCallback);
            return deferred.promise;
        }
    }
} ]);

You need to inject angularSoap in your main app.

angular.module('yourApp', ['angularSoap']);

Then you will have access to a $soap service.

return $soap.post("ws:authentificationRequestParameter", {
    login : login,
    password : password,
    autoLog : autoLog
});

You can also try the angular-soap plugin which didn't work for us in firefox. (fine in chrome).

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks for the reply, so i need to write only this to perform a soap call? Or i need to add something else like the soap request i want to perform?
in the hours of work from my comment, i did this, and i got some error that are making me depressed and unable to keep up with this apprentienship. Here is the punlker of the code, can you help me to get out of this? plnkr.co/edit/ThP70IqhwhQumPd686Nw?p=info
EDIT: Finally I can comunicate with the server, he deny all my request, but atleast I can comunicate (That's a big step forward). The problem now is that the server run SSL, so i need to authenticate myself. how i can do that? I used the angular-soap library you linked before. Here's the code revisited. plnkr.co/edit/ThP70IqhwhQumPd686Nw?p=info Thanks you for the help!
@Wallcraft looks like there's a $soap.setCredentials("username","password"); method. Not sure how you can make it secure though...
Okay, nevermind about my server with SSL, i found a public web server with some simple APIs. I tried to perform a SOAP call and in the console i get this errors -> "XMLHttpRequest cannot load ripedevelopment.com/webservices/LocalTime.asmx?wsdl. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access." and "Uncaught TypeError: Cannot read property 'documentElement' of null" Here's the code plnkr.co/edit/ymko1PvfGD8i5yWEztRU?p=catalogue
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.