I am trying to post data to soap api but unable to do so. i have tried all possible methods but still i get error while calling api.
my api is - http://xyz.asmx?op=UserRegistration
and it excepts data in xml format 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 have tried -
1> With $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 error "unable to process 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 is giving error Cannot read property 'getElementsByTagName' of null
can anyone please help me in this one ? tried almost everything still no luck. thanks in advance
You can use the $http service to POST data to SOAP APIs as below:
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
});
You can also use the plugin angular-soap built on the top of SOAP Client and use $soap service 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;
});
})
Try this :)
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 from your code
I got a response. It was an empty once but a real one :) I used 1 and 2 as DeviceUUID and DevicePushID respectively. Hence an empty response I assume.
Response:
<?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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With