.net WCF REST启动器工具包和RequestInterceptor线程安全
我想从WCF REST初学者工具包中寻找一些关于RequestInterceptor如何工作的技术信息,但没有找到我想要的。让我们看一下从自定义服务主机工厂获取的代码片段:.net WCF REST启动器工具包和RequestInterceptor线程安全,.net,wcf,wcf-rest,wcf-rest-starter-kit,.net,Wcf,Wcf Rest,Wcf Rest Starter Kit,我想从WCF REST初学者工具包中寻找一些关于RequestInterceptor如何工作的技术信息,但没有找到我想要的。让我们看一下从自定义服务主机工厂获取的代码片段: protected override System.ServiceModel.ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses) { var host = (WebServiceHost2)base.Crea
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;
}
受保护的覆盖System.ServiceModel.ServiceHost CreateServiceHost(类型serviceType,Uri[]baseAddresses)
{
var host=(WebServiceHost2)base.CreateServiceHost(serviceType,baseAddresses);
var authenticationProvider=Container.TryGetInstance();
var authorizationRepository=Container.TryGetInstance();
if(authenticationProvider==null)
authenticationProvider=新的DefaultAuthenticationProvider(authorizationRepository);
var securityContext=new securityContext();
Add(新的AuthenticationInterceptor(authenticationProvider,securityContext));
返回主机;
}
代码IncremateServiceHost方法只执行一次
但是,在每个HTTP请求上都会执行AuthenticationInterceptor。正如您所看到的,AuthenticationInterceptor依赖于SecurityContext类和IUserFinder存储库
当多个HTTP请求同时出现时会发生什么情况
我自己找到的。似乎对于给定的请求,在处理下一个请求之前,所有请求拦截器都以线程安全的方式运行。所有请求都将排队,直到第一个请求完成,以通过所有请求拦截器