Initializing the Context
Today's article is about a little-known extensibility point that runs shortly before and after a service invocation takes place. The call context initializer allows you to control the state of the thread that will be used for the service call.
public interface ICallContextInitializer
{
void AfterInvoke(object correlationState);
object BeforeInvoke(InstanceContext instanceContext, IClientChannel channel, Message message);
}
The context initialize runs on the service and first gets called with BeforeInvoke. BeforeInvoke sets up the context state and returns an optional correlation object. That correlation object gets passed in to AfterInvoke so you can use it however you want during cleanup.
Here's the overall sequence of events relevant to the call context.
1.
Initialize the call context
2. Start impersonating the calling identity
3. Make the call
4. Revert the impersonation
5. Run parameter inspectors on the call output
6. Create the response message
7. Uninitialize the call context
As far as I know, the single use for call context initializers so far is in COM+ integration.
Next time: ICallContextInitializer Example
Comments
Anonymous
April 19, 2007
How do I push back against clients that are tying up the external connections of my service? The amountAnonymous
September 22, 2007
During the last series of articles when I covered call context initializers I was primarily talking about