tags:

views:

36

answers:

2

Hi, My applciation works as follows

[user]----username/password/domain----->[WCF service]

then i access the domain server to see to which actual DB the user is associated, after getting that, i validate the user in his actual DB(DB is per domain)

the problem is that i need a place to store the domain name for the following requests against the db.

for example,if the users calls a WCF service operation:

Test()

first the validation procedure is called, (WCF UserNamePasswordValidator) which validates the user password(which is sent as part of the header for REST or as part of the SOAP), and the next function to be called is the Test, but by then i cant tell the domain of the user(to actually serve the request agains that domain..)

I dont want to change the signature of each domain to

Test(string domain)

I cant simply access the headers since i expose the same methods both as REST and as SOAP and the authentication is different for each of them..(one is with headers as with Amazon S3 and the later is using the SOAP standard)

so basically i'm looking for a global, per call storage.(i want to avoid the Per-Call initiation method)

thanks.

EDIT: Maybe i should use the ThreadStaticAttribute? will that work?

+1  A: 

WCF knows a Current OperationContext. You can write your own extensions for it. Unrelated to this issue, I used the same mechanics in this NHibernate Session management here, which may work in its concept for you as well. It accesses the InstanceContext, but the concepts are similar.

flq
Seems nice, will try it out :)
MindFold
+2  A: 

This will not work. You can't store anything in UserNamePasswordValidator. It even doesn't have access to OperationContext because it runs on different thread.

The way to do this is create custom message inspector and extract the information from custom message header to custom operation context extension as Frank mentioned.

Ladislav Mrnka
WOW! thats a huge over-kill for such a simple operation...there must be a more elegant way..
MindFold
Overkill? No it is standard way how to work with custom headers in centralized way.
Ladislav Mrnka