views:

132

answers:

1

If my WCF Service has this attribute:

[ServiceBehavior(
     InstanceContextMode = InstanceContextMode.Single,
     ConcurrencyMode = ConcurrencyMode.Multiple)]

How can the following a Singleton work in a call?

System.ServiceModel.Web.WebOperationContext.Current
+1  A: 

I'm not sure what you're asking exactly... but the operation contexts in WCF (all of them) get tied by default to the execution thread, so whenever you access it (as long as it's within the processing of a WCF request) you'll get the context associated with that requests.

Obviously, your singleton should handle multiple concurrent requests, and it will have access to each request's operation context in the right thread. In other words, most of the time it should just work as expected.

tomasr
So it really works, huh? I'll take your word. I wonder how it works internally, maybe it's Reflector time!
Jader Dias
It's nothing fancy, it just uses the [ThreadStatic] attribute: http://msdn.microsoft.com/en-us/library/system.threadstaticattribute.aspx
tomasr