将数据发布到角度为js的SOAP api
问题描述:
我试图将数据发布到soap api,但无法这样做。 我已经尝试了所有可能的方法,但仍然在调用API时出错。将数据发布到角度为js的SOAP api
我的API是 - http://xyz.asmx?op=UserRegistration
,并以XML格式节选数据,如
<?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>
的事情,我已经尝试 -
1> $ 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'}
});
这给出错误“无法处理请求。 --- >缺少根元素”
2>的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;
这是给错误无法读取空的特性‘的getElementsByTagName’
任何人都可以请帮我在这一个?试过几乎所有的东西仍然没有运气。在此先感谢
答
- 随着$ http.post
可以使用$ http服务为POST数据到SOAP的API如下:
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
});
- 随着angular-soap
您还可以使用构建在SOAP客户端顶部的插件angular-soap并使用$ soap服务实现一样。
例如:
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;
});
})
答
试试这个:)从代码
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'}
});
变化
- 没有发送XML头
- 更改SOAP:Envelope为信封
- 拿出模式命名空间
- 更名皂:身体身体
- 发布到MobileAppService.asmx而不查询字符串
- 发送对象{ “DeviceUUID”: “1”, “DevicePushID”: “2”}不阵列
我收到了回复。这是一个空的一次,但一个真正的:) 我用1和2分别作为DeviceUUID和DevicePushID。因此我承担了一个空洞的回应。
响应:
<?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>