0

While troubleshooting an existing C# WCF web service, I traced an issue to a [ThreadStatic] variable. The variable is modified across many layers and functions. When the variable got corrupted, an exception would occur on all consecutive HTTP calls to run on the thread. Recycling the application pool resolves the problem until the variable gets corrupted again.

Now I'm looking for an alternative. Ideally a property bag with the same lifetime as an HTTP request, so that we can be sure future HTTP calls are not affected by earlier HTTP calls. I came across OperationContext.Current.IncomingMessageProperties which seems to work fine during tests, but the name suggests it's meant for message properties, and not an application variable.

How can I store a variable during the lifetime of an HTTP request?

Andomar
  • 232,371
  • 49
  • 380
  • 404
  • The thing you want to Google is `variable scoped to WCF request` – mjwills Mar 13 '18 at 10:48
  • @mjwills: Thanks. The answer you link to is an empty shell, but it links to this useful answer: https://stackoverflow.com/questions/1895732/where-to-store-data-for-current-wcf-call-is-threadstatic-safe If you change your dupe suggestion to that I can accept it – Andomar Mar 13 '18 at 11:02

0 Answers0