0
我正在寻找一些关于WCF REST入门套件的RequestInterceptor如何工作的技术信息,但是我没有找到我想要的东西。让我们看看自定义服务主机工厂的代码片段:WCF REST StarterKit和RequestInterceptor线程安全
protected override System.ServiceModel.ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
var host = (WebServiceHost2)base.CreateServiceHost(serviceType, baseAddresses);
var authenticationProvider = Container.TryGetInstance<IAuthenticationProvider>();
var authorizationRepository = Container.TryGetInstance<IUserFinder>();
if (authenticationProvider == null)
authenticationProvider = new DefaultAuthenticationProvider(authorizationRepository);
var securityContext = new SecurityContext();
host.Interceptors.Add(new AuthenticationInterceptor(authenticationProvider, securityContext));
return host;
}
该代码inCreateServiceHost方法只执行一次。
但是在每个HTTP请求中都会执行AuthenticationInterceptor。如您所见,AuthenticationInterceptor对SecurityContext类和IUserFinder存储库具有依赖性。
当几个HTTP请求同时发生时会发生什么?
- WCF是否同时执行AuthenticationInterceptor,这意味着SecurityContext和IUserFinder实例应该是线程安全的? IUserFinder依赖于数据库资源。
- 每个请求都被一个接一个地执行,所以AuthenticationInterceptor不能被两个不同的调用同时执行?