Search code examples
c#credentialscsomms-projectproject-server

CSOM C# connect with Project Server


I already ask a similar question and I thought I was making progress. Well turns out I am hard stuck atm.

I am trying to connect to a Project Online Server but I can't.

        string pwaPath = "Url";

        ProjectContext projContext = new ProjectContext(pwaPath);
        // Get the list of projects in Project Web App.
        SecureString password = new SecureString();
        foreach (char c in "password".ToCharArray()) password.AppendChar(c);
        //Using SharePoint method to load Credentials
        projContext.Credentials = new SharePointOnlineCredentials(@"domain\user", password);

        var projects = projContext.Projects;
        int j = 0;
        projContext.Load(projects);
        projContext.ExecuteQuery();
        foreach (PublishedProject pubProj in projContext.Projects)
        {
            Console.WriteLine("\n{0}. {1}   {2} \t{3} \n", j++, pubProj.Id, pubProj.Name, pubProj.CreatedDate);
        }

That's my Test code. Using the SharePointOnlineCredentials I get an Error

System.ArgumentException: 'The 'username' argument is invalid.'

So I tried using [email protected] as the user and got

The response header value is 'NTLM'

Because of that, I tried using NetworkCredentialand got this error:

The specified server may not support APIs used in this operation.

My last hope was to test FormsAuthentication. Here are the code and the error I got

projContext.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;    
FormsAuthenticationLoginInfo formsAuthInfo = new  FormsAuthenticationLoginInfo("user", "password");
projContext.FormsAuthenticationLoginInfo = formsAuthInfo;

'Server was unable to process request. ---> Site is not configured for Claims Forms Authentication.

maybe someone has an idea what I can try.


Solution

  • Found the mistake. I had to add the dlls from the server as a reference and not the Nuget Microsoft.SharePointOnline.CSOM