开发者

WCF REST StarterKit and RequestInterceptor thread safety

I was looking for some technical information about how RequestInterceptor from the WCF REST starter kit works, but I didn't find what I wanted. Let's look at the code snippet took from the custom service host factory:

    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;
    }

That code inCreateServiceHost method is only executed once.

However on every HTTP request AuthenticationInterceptor is executed. As you can see AuthenticationInterceptor开发者_JS百科 has dependencies on SecurityContext class and IUserFinder repository.

What happens when several HTTP request come at the same time?

  1. Does WCF execute AuthenticationInterceptor concurrently which means that SecurityContext and IUserFinder instance should be thread safe? IUserFinder depends on data base resources.
  2. Each request is executed one after another so AuthenticationInterceptor can't be executed concurrently by two different calls?


I found it on my own. It seems that for a given request all RequestInterceptors are run in a thread safe manner before the next request is handled. All requests are queued until the first request finish to go through all the request interceptors.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜