Kevin
Kevin

Reputation: 185

WCF how to pass token for authentication?

I have a WCF service which would like to support basicHttpBinding and webHttpBinding. When the client successfully login, server will generate a token for client to pass to server on all the request make later. Question is how the client can pass the token to server? I don't want to add an extra parameter on every web method to hold the token.

Upvotes: 16

Views: 14423

Answers (1)

marc_s
marc_s

Reputation: 754220

Typically, the best way to do something like this is passing such "meta-information" in a WCF header. You can easily create a message inspector to extend WCF (it's really not that scary and hard to do!) which would inject the token into every outgoing request from the client, and retrieve it from the header and validate it on the server side.

There are a number of pretty good blog post out there showing you how to create a message inspector:

Check out the two relevant interfaces to implement:

Upvotes: 20

Related Questions