我为移动使用离子框架创建应用程序通过ASP.NET webservice连接到sql server 2008。当我使用SOAP头时,AngularJs $http.post()
不发送数据。
登录方式
public AuthHeader Authentication;
[SoapHeader("Authentication", Required = true)]
[WebMethod(Description = "Returns login User")]
public string Login(string Username, string Password)
{
if (Authentication.Username.ToLower() != "admin" ||
Authentication.Password.ToLower() != "admin@123")
throw new SoapException("Unauthorized",
SoapException.ClientFaultCode);
Password = Encrypt.GetSHA1HashData(Password);
var result = EmployeeService.Login(Username, Password);
if (result == null)
return "-1";
return JsonConvert.SerializeObject(result);
}
Angular Service
.service('LoginService', function ($q, $http) {
return {
loginUser: function (name, pw) {
var deferred = $q.defer();
var promise = deferred.promise;
$http.post('http://192.168.187.1/SalesServices/MobileService.asmx/Login',
{
Username: 'thao.huynh',
Password: 'thao.huynh'
}).then(function (response) {
deferred.resolve(response.data);
// console.log(response.data);
}).catch(function (response) {
deferred.reject('error', response.status, response.data);
console.error('error', response.status, response.data);
}).finally(function () {
// console.log("finally finished gists");
});
promise.success = function (fn) {
promise.then(fn);
return promise;
}
promise.error = function (fn) {
promise.then(null, fn);
return promise;
}
return promise;
}
}
答案 0 :(得分:0)
为此你可以参考这个答案...... 它显示了使用soap
调用服务的最简单方法