Question

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 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?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top