javascript - How to return the soapresponse from interceptor's response -



javascript - How to return the soapresponse from interceptor's response -

i creating soap request interceptor angularjs

it looks this:

angular.module('myapp') .factory('soapinterceptor', ['$q', function ($q) { var soaprequest = function (url, soapaction, requestenvelope, callback) { $.soap({ url: url, appendmethodtourl: false, soapaction: soapaction, enablelogging: false, data: requestenvelope, success: function (soapresponse) { callback(soapresponse.tojson()); }, error: function (soapresponse) { throw new error(soapresponse); } }); } homecoming { 'request': function (config) { if (config.data && config.data.issoap) { var deferred = $q.defer(); soaprequest(config.url, config.data.soapaction, config.data.requestenvelope, function (data) { angular.extend(data, config); deferred.resolve(data); }); homecoming deferred.promise; } homecoming config; }, 'response': function (response) { // somehow want returned response soap response // have got in request of course of study it's no utilize there homecoming response; } } }]);

so can consume within datastore's method this:

var deferred = $q.defer(); $http.post("http://myapi.com/service.asmx", { issoap: true, requestenvelope: reqxml, soapaction: "http://myapi.com/campaignsgetlist" }) .success(function (data) { deferred.resolve(data); }); homecoming deferred.promise;

when issoap true request correctly passed soaprequest how can pass response returned response function consumer can happily utilize promise?

any help appreciated.

if understood correctly trying override behaviour of $http service when info of request content has flag issoap set true. looking @ code seems want handle $http phone call using interceptors.

the problem interceptors not meant used that, interceptors supposed handle things before and/or after http request happens, not supposed handle http request themselves.

however, think want this:

define own "httpsoap service", this:

app.service('httpsoap', ['$q', function ($q) { homecoming function (url, soapaction, requestenvelope) { var deferred = $q.defer(); $.soap({ url: url, appendmethodtourl: false, soapaction: soapaction, enablelogging: false, data: requestenvelope, success: function (soapresponse) { deferred.resolve(soapresponse.tojson()); }, error: function (soapresponse) { deferred.reject(soapresponse) } }); homecoming deferred.promise; } }]);

and utilize this:

app.controller('mycontroller', function ($scope, httpsoap) { // other code here assume define // reqxml variable httpsoap("http://proxy-send.concep.com/service.asmx", "http://new.cl.truelogic.com.au/campaignsgetlist", reqxml) .then(function (jsondata) { //things went }, function (errorresponse) { //something bad happened }); });

a couple other things point out:

what doing in sec code snipped of question "deferred anti-pattern" mutual bad practice tends happen among people starting familiar promises. used fall time when got started angular.

notice got rid of callback parameter had within function of factory, since it's bad thought utilize callbacks in angular, it's much improve utilize $q promise instead.

javascript angularjs soap

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -