views:

52

answers:

1

Hi,

We are using an authentication string (guid) for client identification in our wcf services and for database lookups. We dont want to add this to every messagecontract.

Is there a way to do this in wcf?

Regards, Rune

+1  A: 

The best and typical way is to add this to a header in your WCF message - and that would be perfect in a message contract.

Why do you not want to add it to the message contract??

WCF typically encourages a "per-call" methodology - you send all necessary info with your call, each and every call that is. It is discouraged to have any kind of "state" that lingers around between calls.

So again: why not just include your authentication string as a header in every message? That's the preferred way of doing things these days.

UPDATE:

Check out Nicholas Allen's blog post on Adding Headers to a Call. Besides adding them to the message contract, you could also check out the Message Inspector sample he links to, which creates a message inspector that automagically adds those header entries to each outgoing call. No code clutter, no mess, nothing - just works.

marc_s
Hi, I want to keep my message contracts clean and to avoid code duplication, if possible.
Rune
yes, ok -this is neither code duplication, nor do you clutter up your message contracts. Using message headers is **the** standard way of doing this kind of thing - anything else quickly turns into a hack....
marc_s