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'm facing some problems accessing by Claim Based to my web service.

On my App there's only Claim Based: windows auth is disabled and NTLM also. If I access to Sharepoint by web based interface, this recognise me as UserX and everything goes.

If I access by WS there are 2 scenarios:

  • Call by UserY (System Account) -> Everything goes well
  • Call by UserX (NO SA but SCAdmin) -> Object reference not set to an instance of an object

The code is very simple, gets only current user Login Name:

using (SPSite sito = new SPSite("https://to0wss2k10rey03:50000/sites/Test1"))
                using (SPWeb web = sito.OpenWeb())
                    string Username =  web.CurrentUser.LoginName;

The exception is raised when i try to get the CurrentUser, wich appears to be null..

share|improve this question
Hmmm... where are you using the web services? This is plain 'ol server side OM code!? Do you run this in a console app, in a web part...? Which line do you get the null ref exception? Please provide us with more details... – Wictor Wilen MCA MCM MVP May 15 '12 at 17:06
up vote 2 down vote accepted

I'm quiet mystified by how it works with UserY, it should always fail.

When running with Claims without NTLM the only way to pass credentials is through a FedAuth cookie with your SharePoint STS SAML token. To get that token you have to call the SharePoint STS with a SAML token from your identityprovider (ADFS?). To get that token you have to call the identity provider with login info.

See Claims Proxy – A C# Library for Calling Claims Protected Web Services Connecting to SharePoint with Claims Authentication or the main blog about SharePoint with claims Share-n-dipity

share|improve this answer

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.