我想使用WCF或Web API在REST中创建登录服务。
使用MVC项目模板,它会为我生成如下服务:
getValues()
getValue(int)
deleteValue(int)
updateValue(int,post)
但是,我希望checkLogin(username, password)
之类的服务返回true
或false
。当前模板只允许我添加标识api/values/5
,我无法将其转换为查询字符串api/values/user=123&pass=123
,因为它报告路径包含&
,这是不安全的。请帮忙。感谢
答案 0 :(得分:0)
解决方法如下:(WCF VS-Project)
Public Function Login(ByVal user As String, ByVal pass As String) As String Implements IBasicService.Login
If user Is Nothing Or pass Is Nothing Then
Return "No"
End If
Dim con = cnc.grpconection
Dim com = con.CreateCommand()
com.CommandText = "select * from Emp where UserName = @usr AND password = @pass"
com.Parameters.AddWithValue("@usr", user)
com.Parameters.AddWithValue("@pass", pass)
con.Open()
Dim reader = com.ExecuteReader()
Try
reader.Read()
If reader.HasRows Then
Return "Yes"
End If
Return "No"
Finally
reader.Close()
com.Dispose()
con.Close()
End Try
End Function
使用界面功能
<OperationContract()>
<WebInvoke(Method:="GET", ResponseFormat:=WebMessageFormat.Xml, BodyStyle:=WebMessageBodyStyle.Bare, UriTemplate:="login?user={user}&pass={pass}")>
Function Login(ByVal user As String, ByVal pass As String) As String
感谢这篇优秀的文章www.topwcftutorials.net/2013/09/simple-steps-for-restful-service.html