我有自定义用户auth会话的标准Hello World Web服务,因为我想要一些额外的参数。身份验证部分按预期工作。以下是我的CustomUserSession:
public class CustomUserSession : AuthUserSession
{
public int? PortalId { get; set; }
public override void OnAuthenticated(ServiceInterface.IServiceBase authService, IAuthSession session, IOAuthTokens tokens, Dictionary<string, string> authInfo)
{
base.OnAuthenticated(authService, session, tokens, authInfo);
var refId = session.UserAuthId;
var userRep = new InMemoryAuthRepository();
var userAuth = userRep.GetUserAuth(refId.ToString());
PortalId = userAuth.RefId;
}
}
我让refId从我的其他表中保存一个自定义参数,并在调试时得到正确的值。我的问题是,我现在可以从这个方法中调用webservice的方法吗?那么,例如,如果我有一个接受int的execute方法,我可以在重写的OnAuthenticated方法中调用它吗?
答案 0 :(得分:2)
您可以使用ResolveService<T>
在ServiceStack中执行服务。
从自定义用户会话中:
using (var service = authService.ResolveService<MyService>())
{
var response = service.Get(new MyRequest { ... });
}
从ServiceStack服务内部:
using (var service = base.ResolveService<MyService>())
{
var response = service.Get(new MyRequest { ... });
}
来自ServiceStack外部:
using (var service = HostContext.ResolveService<MyService>())
{
var response = service.Get(new MyRequest { ... });
}
答案 1 :(得分:0)
尝试将ServiceInterface.IServiceBase
解析为正确的类/接口。
以下是IDbConnectionFactory
的示例:
//Resolve the DbFactory from the IOC and persist the info
authService.TryResolve<IDbConnectionFactory>().Exec(dbCmd => dbCmd.Save(PortalId));