【发布时间】:2014-03-17 23:38:59
【问题描述】:
我正在使用“RememberMe=true”,并希望我的服务客户端重新使用打开的会话(如果可用)。我从下面的链接中获得了大部分代码 - 此代码有效,但每次验证都失败并重新验证。我是否必须以某种方式发送 ss-pid cookie?
还有一点需要注意:这是一个访问我的 servicestack 服务的 WinForms 客户端。
ServiceStack JsonServiceClient OnAuthenticationRequired
我的代码
Private Shared _UserName As String = "xxxxx"
Private Shared _Password As String = "yyyyy"
Private Shared _clientAuthenticationRequested As New Action(Of WebRequest)(AddressOf InteractiveAuthentication)
Public Shared ReadOnly Property ServiceClient() As JsonServiceClient
Get
If _serviceClient Is Nothing Then
_serviceClient = New JsonServiceClient(ServiceContext.ServiceUrl)
_serviceClient.OnAuthenticationRequired = _clientAuthenticationRequested
_serviceClient.UserName = _UserName
_serviceClient.Password = _Password
//service requiring authentication
Dim v = _serviceClient.Get(Of Tonto.Svc.Model.AppConstants)(
New Tonto.Svc.Model.AppConstants())
End If
Return _serviceClient
End Get
End Property
Private Shared Sub InteractiveAuthentication(sourcerequest As System.Net.WebRequest)
Dim v = _serviceClient.Send(Of ServiceStack.AuthenticateResponse)(
New ServiceStack.Authenticate() With {
.UserName = _UserName,
.Password = _Password,
.RememberMe = True})
End Sub
【问题讨论】:
标签: authentication servicestack