0

We have a client-server architecture with WCF on the server side. All WCFs are per-call; basically each WCF method is a transaction script. When a WCF-method gets called, client passes some authentication information (let's say for simplicity, user ID). This ID (along with some other user-related info) is than needed everywhere in the logic layer to check permissions for pulling some objects from DB, to answer in appropriate language and so on.

Currently we packed all this info into a "RequestBag"-object somewhere centrally when request arrives and passed it along to classes in logic. This however results that it's passed pretty much everywhere.

Is there a better way? Basically what I would like to do is call some static method and say GetCurrentUserState(), which would give me data relevant for the context of current WCF call. But how to do this? Thread ID is not an option, for some threads can be started to do some tasks. MSDN says

"There is no general data store associated with a WCF session"

. Does this mean that passing my object everywhere IS actually a way to do this?

VVN
  • 1,607
  • 2
  • 16
  • 25
Maxim Zabolotskikh
  • 3,091
  • 20
  • 21
  • http://stackoverflow.com/help/mcve – Amit Kumar Ghosh Feb 25 '16 at 08:20
  • 1
    There's nothing wrong with passing authentication info per call, that's how the www works anyway. I think the problem is that you are trying to fuse saved user state in a `static` with a `PerCall` service. Maybe what you should do is make your service `PerSession` then such info can easily be saved in the service class without need for singletons or statics. –  Feb 25 '16 at 08:28

1 Answers1

0

Perhaps the question was posed not in the best way, as I didn't receive much feedback. Anyway, if smb else stumbles upon this, this is the thread that actually has answer to my question Where to store data for current WCF call? Is ThreadStatic safe?

So I ended up subclassing MyContext:IExtension<OperationContext> and putting my user state there. Than I can just access it as MyContext.Current.MyUserState throughout the application.

Community
  • 1
  • 1
Maxim Zabolotskikh
  • 3,091
  • 20
  • 21