Question

If I have both IParameterInspector and IErrorHandler attached to a service can I be sure IErrorHandler.HandleError() will be called on the same thread where IParameterInspector.BeforeCall() is called?

I need this because in case of a fault thrown IParameterInspector.AfterCall() is never called and there is no way (as far as I know) I can get correlation state object created in BeforeCall(). So I hope to overcome this by having a ThreadStatic field in my implementation of the interfaces :(

Was it helpful?

Solution

You may want to utilize Instance Context Extensions.

InstanceContextExtension: IExtension<InstanceContext>   
OperationContext.Current.InstanceContext.Extensions.Find<InstanceContextExtension>()

The instance context extension can be added in BeforeCall method. The instance context extension can then be retrieved in AfterCall method and used. Any operation specific data can be put in this extension object instead of introducing thread affinity.

OTHER TIPS

You could have your class that implements IErrorHandler also implement IParameterInspector. You could then store references to your correlation state and input parameters as class variables. Then they would be accessable from within the HandleError method. I'm currently using this for logging input parameters and the raw message whenever an unhandled exception occurs.

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