WCF OperationContext is null after await

WCF

Assume we have some action in our WCF service like this:


public async Task<MyResponse> DoSomething() 
{
	//Here the OperationContext.Current is not null
    
    await Task.Run(() => {
    ...
    });
    
    //Here the OperationContext.Current is null.

}

That happens even though the ConfigureAwait is false by true by default and it should return to the original synchronization context.

To fix this in WCF we need to set this key/value in appsettings:


	<add key="wcf:disableOperationContextAsyncFlow" value="false" />

Post a Comment

Previous Post Next Post