0
我正在一个项目中,我必须从Android客户端应用程序访问后端服务进行用户认证。因此,我创建了具有以下结构的WCF REST服务。如何从Android客户端调用REST WCF服务
//<summary>
// Checks whether user is exists or not
// </summary>
// <param name="UserName"></param>
// <param name="Password"></param>
// <returns></returns>
[OperationContract]
[WebGet(UriTemplate = "IsUserExist/{UserName}/{Password}", ResponseFormat = WebMessageFormat.Json)]
bool IsUserExist(string UserName, string Password);
// <summary>
// Log the time of specified user
// </summary>
// <param name="UserName"></param>
[OperationContract]
[WebGet(UriTemplate = "LogTime/{username}", ResponseFormat = WebMessageFormat.Json)]
string LogTime(string UserName);
而且我已经在IIS中成功部署了它。我可以轻松地从浏览器调用服务来执行用户认证,这很好。
http://localhost:9001/HNNDataSerivce/LogInService.svc/IsUserExist/Bob/pass123
http://localhost:9001/HNNDataSerivce/LogInService.svc/LogTime/Bob
而这个服务调用分别返回所需的值作为布尔和字符串。
现在我想从android客户端进行相同的服务调用。为此我创建了一个带有文本框和按钮的简单演示应用程序。如果用户在文本框中指定了用户名和密码,并且用户单击了按钮,我想实现以下认证过程。
public void LoginButtonClick(View v) {
if(IsUserExist(UserName, Password))
LogTime(UserName)
else
// show invalid user message
}
寻找Android的改造 – j2emanue
作为旁白的问题:为什么是** Login **方法称为IsUserExists? –
@cFrozenDeath调用IsUserExists的原因是为了确保指定的用户是否存在于数据库中。如果它存在,则会调用LogTime函数来记录日志记录的时间。 – nabin