I am using async/await pattern in .NET 4.5 to implement some service methods in WCF. Example service:
Contract:
[ServiceContract(Namespace = \"http:/
Fortunately for us, our real-life service implementation gets instantiated via Unity
IoC container. That allowed us to create a IWcfOperationContext
which was configured to have a PerResolveLifetimeManager
which simply means that there will be only one instance of WcfOperationContext
for each instance of our RealService
.
In the constructor of WcfOperationContext
we capture OperationContext.Current
and then all the places that require it get it from IWcfOperationContext
. This is in effect what Stephen Cleary suggested in his answer.