SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am creating a custom wcf service deployed on sharepoint. How to pass the current user's credentials to the service (from a web part)? Do i have to use these helpers: SPChannelFactoryOperations.ConfigureCredentials SPChannelFactoryOperations.CreateChannelActingAsLoggedOnUser

Should it be possible to get this working with oob SharePoint service factory? Or should I shift to wsHttpBinding?

share|improve this question

you can pass the users token to the wcf service token of current user can be found as follows:

SPWeb myWeb = SPContext.Current.Web;
SPUser user = myWeb.CurrentUser
SPUserToken token = user.UserToken

SPUserToken Refrence

share|improve this answer
I'm using windows authentication so shouldn't the user authenticate automatically? – thomius Mar 19 '12 at 12:05
ok i see you want to just pass his username and pass to the wcf service as parameters and not for authentication? – Sebastien Stettler Mar 19 '12 at 12:13
I'd like to authenticate the logged on user in the service. But when trying to read SPUser from SPContext.Current.Web it throws an exception for some reason. Should it work just oob in the web service (when called from a web part)? – thomius Mar 19 '12 at 12:20
I mean, via REST directly from the browser everything works fine and I can access the SharePoint API and the logged user's credentials (either via http or https). But when accessed via SOAP from my web part the wcf throws at SPContext.Current.Web.CurrentUser and authenticates as the process account the web part is running on. – thomius Mar 19 '12 at 12:28
what exception does it throw i do see your challange though – Sebastien Stettler Mar 19 '12 at 12:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.