1
我正在将Wcf REST服务用于Angular JS应用程序。我正在根据用户名和密码创建userlogin网站。我的Wcf服务获得布尔方法返回true或false。但问题是,我提供的输入字段中提供的用户名信息,我的脚本文件代码始终回复真实。Angular JS脚本应用程序始终使用Wcf服务重新执行
这里是我的接口..
[OperationContract]
[WebInvoke(Method = "GET",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
//BodyStyle = WebMessageBodyStyle.WrappedRequest,
UriTemplate = "/AuthenticateUser")]
bool AuthenticateUser(UserLogin userLogin);
下面是接口的实现..
public bool AuthenticateUser(UserLogin userLogin)
{
string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("spAuthenticateUser", con);
cmd.CommandType = CommandType.StoredProcedure;
string encryptedpassword = FormsAuthentication.HashPasswordForStoringInConfigFile(userLogin.Password, "SHA1");
SqlParameter paramUsername = new SqlParameter("@UserName", userLogin.Username);
SqlParameter paramPassword = new SqlParameter("@Password", encryptedpassword);
cmd.Parameters.Add(paramUsername);
cmd.Parameters.Add(paramPassword);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
int RetryAttempts = Convert.ToInt32(rdr["RetryAttempts"]);
if (Convert.ToBoolean(rdr["AccountLocked"]))
{
return false;
}
else if (RetryAttempts > 0)
{
int AttemptsLeft = (4 - RetryAttempts);
return true;
}
else if (Convert.ToBoolean(rdr["Authenticated"]))
{
return true;
}
}
return true;
}
}
这里是我的脚本文件代码..
///// <reference path="../angular.min.js" />
var app = angular.module("WebClientModule", [])
.controller('Web_Client_Controller', ["$scope", 'myService', function ($scope, myService) {
$scope.OperType = 1;
//1 Mean New Entry
//To Clear all input controls.
function ClearModels() {
$scope.OperType = 1;
$scope.Username = "";
$scope.Password = "";
}
$scope.login = function() {
var User = {
Username: $scope.Username,
Password: $scope.Password,
};
myService.AuthenticateUser(User).then(function (pl) {
console.log(pl.data)
if (pl.data) {
$scope.msg = "Password or username is correct !"
}
else {
$scope.msg = "Password Incorrect !";
console.log("Some error Occured" + err);
}
}, function (err) {
$scope.msg = "Password or username is Incorrect !";
console.log("Some error Occured" + err);
});
};
}]);
app.service("myService", function ($http) {
this.AuthenticateUser = function (User) {
return $http.post("http://localhost:52098/HalifaxIISService.svc/AuthenticateUser", JSON.stringify(User));
}
})
这里是当我运行应用程序时输出..
请提供您的宝贵意见,以纠正此错误。
有一切就OK了。在脚本文件?? – Mohammad
@Mohammad您是否按照提及的方式尝试 – Sajeetharan
仍然会返回true并始终显示此消息... $ scope.msg =“密码或用户名正确无误!” – Mohammad