locked
Need help to fix this issue - CSOM Project Server 2016 RRS feed

  • Question

  • Dear Experts

    I am new to CSOM (Project Server 2016). Getting below error when i ran sample CSOM Project Server 2016

    Code

             

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using  Microsoft.ProjectServer.Client;
    using Microsoft.SharePoint.Client;

    namespace CSOM_Test
    {
        class Program
        {
            private const string pwaPath = "https://ProjectServer2016/PWA";
            private static string basicEpt = "Enterprise Project";
            private static ProjectContext projContext;
            private static string projName = "CSOM2";
            static void Main(string[] args)
            {
                Console.WriteLine("Test");
                projContext = new ProjectContext(pwaPath);
                System.Security.SecureString password = new System.Security.SecureString();
                foreach (char c in "mypassword".ToCharArray()) password.AppendChar(c);
                projContext.Credentials = new SharePointOnlineCredentials("santosh@mydomain.com",password);
                try
                {
                    ProjectCreationInformation newproj = new ProjectCreationInformation();
                    newproj.Id = Guid.NewGuid();
                    newproj.Name = projName;
                    newproj.Description = "Test creating a project with CSOM1";
                    newproj.Start = DateTime.Today.Date;

    newproj.EnterpriseProjectTypeId = GetEptUid(basicEpt);

                    PublishedProject newpublishProj = projContext.Projects.Add(newproj);
                    QueueJob qjob = projContext.Projects.Update();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
                Console.ReadLine();
            }

        }
    }

    I didn't understand what could be the issue. Is there anything wrong in my code ? Can someone help me

    Regards

    Santosh

    Sunday, September 25, 2016 5:51 PM

All replies

  • Santosh,

    It seems like you're trying to authenticate with Project Online while the URL in your example seems like it's On Premise. If that is the case, set the credentials as follows:

    using (var projContext = new ProjectContext(pwaPath))
    {
     projectContext.Credentials = CredentialCache.DefaultCredentials;
     ...
    }

    Hope this helps,

    Roy



    Royg

    Monday, September 26, 2016 8:06 AM
  • Hi Roy

    Thanks a ton for your response. Its on Premise

    However getting same error. Any Idea ?

    An unhandled exception of type 'System.Net.WebException' occurred in Microsoft.SharePoint.Client.dll

    Additional information: The remote server returned an error: (403) Forbidden.

    Regards

    Santosh

    Monday, September 26, 2016 11:55 AM
  • Santosh,

    This is a different error (403 as oppose to 401), this happens since you're using SSL.

    Try replacing the credentials line again:

    projectContext.Credentials = new NetworkCredential("username", "password", "domain");

    *Use your active directory credentials.

    let me know if this solves it.

    Roy


    Royg

    Monday, September 26, 2016 2:14 PM
  • Thanks Roy.

    I have already implemented same line in my solution but no luck

    Sample code

    System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("santosh, "santosh@123", "mydomain");
                projContext = new ProjectContext(pwaPath);
                projContext.Credentials = credentials;
                projContext.Load(projContext.Projects);
                projContext.ExecuteQuery(); => Getting Error

     Error :

    An unhandled exception of type 'System.Net.WebException' occurred in Microsoft.SharePoint.Client.dll

    Additional information: The remote server returned an error: (403) Forbidden.

    Regards

    Santosh


    Monday, September 26, 2016 6:24 PM