2016-08-28 85 views
1

即時通訊在這個領域的新技術,我正在做一個apprentienship,這個appreintienship的目標,正在製作一個應用程序,從一個運行SOAP的服務器檢索數據(不幸),這是我第一次請求開發者'關於服務器內的所有者的一些信息。這個調用不起作用(我肯定在我的代碼中寫了sh * t),我不知道如何改正它並做出更好的SOAP調用。 下面的代碼AngularJS SOAP調用

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(); 
    }; 
}); 

感謝大家對anticipately技巧和提示!

回答

0

SOAP是Web應用程序可能發生的最糟糕的事情。

對於我們的應用程序,我們使用javascript SOAP client library

在你的角度應用程序,你需要創建一個模塊工廠:

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; 
     } 
    } 
} ]); 

你需要在你的主應用程序注入angularSoap

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

然後,您將有權訪問$soap服務。

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

你也可以試試angular-soap插件,它在firefox中不適合我們。 (罰款鉻)。

+0

感謝您的回覆,所以我需要只寫這個來執行肥皂呼叫?或者我需要添加其他的東西,比如我想要執行的肥皂請求? – Wallcraft

+0

在我評論的工作時間內,我做到了這一點,並且我得到了一些令我沮喪的錯誤,無法跟上這個實習生的步伐。 這裏是代碼的punlker,你能幫我擺脫這個嗎? https://plnkr.co/edit/ThP70IqhwhQumPd686Nw?p=info – Wallcraft

+0

編輯: 最後,我可以與服務器交流,他否認我的所有要求,但至少我可以交流(這是一大進步)。現在的問題是服務器運行SSL,所以我需要驗證自己。我該怎麼做?我使用了之前鏈接的角度肥皂庫。這是重新編寫的代碼。 https://plnkr.co/edit/ThP70IqhwhQumPd686Nw?p=info 感謝您的幫助! – Wallcraft