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?

1 Answer 1


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

  • I'm using windows authentication so shouldn't the user authenticate automatically?
    – thomius
    Mar 19, 2012 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? Mar 19, 2012 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, 2012 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, 2012 at 12:28
  • what exception does it throw i do see your challange though Mar 19, 2012 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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