Post data to SOAP api using angular js

I am trying to send data in soap api but cannot do this. I tried all possible methods, but still get an error when calling api.

my api is http: //xyz.asmx? op = UserRegistration

and it excludes xml data like

<?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:Body> <UserRegistration xmlns="http://Service/"> <Usercreditional>string</Usercreditional> </UserRegistration> </soap:Body> </soap:Envelope> 

Things I tried -

1> From $ http.post

  var soapData = '<?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:Body>'+ '<UserRegistration xmlns="http://Service/">'+ '<Usercreditional>[{ \'DeviceUUID\': \'' + data.DeviceUUID + '\', ' + "\"DevicePushID\":\"" + data.DevicePushID + "\"}]" + '</Usercreditional></UserRegistration></soap:Body></soap:Envelope>'; return $http({ method: 'POST', url: ' http://xyz.asmx?op=UserRegistration', data : soapData, headers : { "Content-Type" : 'application/xml'} }); 

this gives the error "cannot process the request. ---> Root element is missing"

2> With SOAPClient

  var deferred = $q.defer(); var soapParams = new SOAPClientParameters(); var userCredentials = [{"DeviceUUID": data.DeviceUUID, "DevicePushID": data.DevicePushID}]; for (var param in userCredentials ) { soapParams.add(param, soapParams[param]); } var soapCallback = function (e) { if (e.constructor.toString().indexOf("function Error()") != -1) { deferred.reject(e); } else { deferred.resolve(e); } }; SOAPClient.invoke(' http://xyz.asmx', 'UserRegistration', soapParams, true, soapCallback); return deferred.promise; 

this gives an error Unable to read the getElementsByTagName property from null

Can someone help me with this? tried almost everything still out of luck. thanks in advance

+7
javascript angularjs soap web-services ionic-framework
source share
2 answers
  • From $ http.post

You can use the $ http service for POST data for the SOAP API, as shown below:

enter image description here

 var headers = { 'Content-Type': 'text/xml; charset=utf-8' }; return $http({ method: 'POST', url: 'http://providerservice.fmcnetwork.net/MobileAppService.asmx?op=UserRegistration', data : soapData, headers : headers }); 
  1. With angular-soap

You can also use the angular-soap plugin built on top of the SOAP client and use $ soap to achieve the same.

For example:

 angular.module('myApp', ['angularSoap']) .factory("testService", ['$soap',function($soap){ var base_url = "http://www.cooldomain.com/SoapTest/webservicedemo.asmx"; return { CreateUser: function(firstName, lastName){ return $soap.post(base_url,"CreateUser", {firstName: firstName, lastName: lastName}); } } }]) .controller('MainCtrl', function($scope, testService) { testService.CreateUser($scope.firstName, $scope.lastName).then(function(response){ $scope.response = response; }); }) 
+5
source share

Try the following :)

  var soapData = '<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">'+ '<Body>'+ '<UserRegistration xmlns="http://FmcMobileApplicationService/">'+ '<Usercreditional>{ \'DeviceUUID\': \'' + data.DeviceUUID + '\', ' + "\"DevicePushID\":\"" + data.DevicePushID + "\"}" + '</Usercreditional></UserRegistration></Body></Envelope>'; return $http({ method: 'POST', url: 'http://providerservice.fmcnetwork.net/MobileAppService.asmx' data : soapData, headers : { "Content-Type" : 'application/xml'} }); 

Changes in your code

  • Didn't send xml header
  • Modified Soap: Envelope to Envelope
  • Invoked schema namespaces
  • Renamed Soap: Body to Body
  • Submitted to MobileAppService.asmx without request
  • Sent object {"DeviceUUID": "1", "DevicePushID": "2"} not an array

I got an answer. It was empty, but real! I used 1 and 2 as DeviceUUID and DevicePushID respectively. Therefore, I assume that the answer is empty.

Answer:

 <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <UserRegistrationResponse xmlns="http://FmcMobileApplicationService/"> <UserRegistrationResult>[]</UserRegistrationResult> </UserRegistrationResponse> </soap:Body> </soap:Envelope> 
+2
source share

All Articles