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 -
and it excepts data in xml format like
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soap="/">
<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="" xmlns:xsd="" xmlns:soap="/">'+
'<soap:Body>'+
'<UserRegistration xmlns="http://Service/">'+
'<Usercreditional>[{ \'DeviceUUID\': \'' + data.DeviceUUID + '\', ' +
"\"DevicePushID\":\"" + data.DevicePushID + "\"}]" +
'</Usercreditional></UserRegistration></soap:Body></soap:Envelope>';
return $http({
method: 'POST',
url: ' ',
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(' ', '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
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/2001/XMLSchema-instance" xmlns:xsd="http://www.w3/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap/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/2001/XMLSchema-instance" xmlns:xsd="http://www.w3/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap/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
Share Improve this question edited May 8, 2017 at 7:31 Vikas Vanvi asked Apr 26, 2017 at 9:47 Vikas VanviVikas Vanvi 4624 silver badges18 bronze badges2 Answers
Reset to default 5 +25- With $http.post
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/MobileAppService.asmx?op=UserRegistration',
data : soapData,
headers : headers
});
- With angular-soap
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./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/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/MobileAppService.asmx'
data : soapData,
headers : { "Content-Type" : 'application/xml'}
});
Changes from your code
- Didn't send the xml header
- Changed soap:Envelope to Envelope
- Took out the schema namespaces
- Renamed soap:Body to body
- Posted to MobileAppService.asmx without the querystring
- Sent an object { "DeviceUUID": "1", "DevicePushID": "2" } not an array
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/soap/envelope/" xmlns:xsi="http://www.w3/2001/XMLSchema-instance" xmlns:xsd="http://www.w3/2001/XMLSchema">
<soap:Body>
<UserRegistrationResponse xmlns="http://FmcMobileApplicationService/">
<UserRegistrationResult>[]</UserRegistrationResult>
</UserRegistrationResponse>
</soap:Body>
</soap:Envelope>