Here is the complete console code to fetch list of projects along with Site URL.
- New C# project.
- Add following web service references:
- http://projectserver/PWA/_vti_bin/projects.asmx?wsdl as SvcProject
- http://projectserver/PWA/_vti_bin/LoginWindows.asmx?wsdl as SvcLoginWindows
- http://projectserver/PWA/_vti_bin/psi/wssinterop.asmx?wsdl as Svcwssinterop
- Copy below code into program.cs
Reference: Prerequisites for ASMX-based code samples in Project 2013.
using System; using System.Data; using System.Net; using PSLibrary = Microsoft.Office.Project.Server.Library; namespace ConsoleApplication1 { class Program { private const string PROJECT_SERVER_URL = "http://projectserver/pwa/_vti_bin/psi/"; static void Main(string[] args) { bool isWindowsUser = true; // Create an instance of the project object. ProjectDerived project = new ProjectDerived(); project.Url = PROJECT_SERVER_URL + "Project.asmx"; project.Credentials = CredentialCache.DefaultCredentials; try { // The program works on a Windows-auth-only computer if you comment-out the // following line. The line is required for multiple authentication. project.CookieContainer = GetLogonCookie(); project.EnforceWindowsAuth = isWindowsUser; SvcProject.ProjectDataSet projectDs = project.ReadProjectList(); ProjectInfo prjInfo = new ProjectInfo(); foreach(SvcProject.ProjectDataSet.ProjectRow projectRow in projectDs.Project) { Console.WriteLine(projectRow.PROJ_NAME + " (" + projectRow.PROJ_UID + ")-" + prjInfo.GetSiteInfo((Guid) projectRow.PROJ_UID)); } // Get a list of all published projects. // Use ReadProjectStatus instead of ReadProjectList, // because the permission requirements are lower. //SvcProject.ProjectDataSet projectDs = // project.ReadProjectStatus(Guid.Empty, // SvcProject.DataStoreEnum.PublishedStore, // string.Empty, // (int)PSLibrary.Project.ProjectType.Project); //Console.WriteLine(string.Format( // "There are {0} published projects.", // projectDs.Project.Rows.Count)); } catch (UnauthorizedAccessException ex) { Console.WriteLine(ex.Message); } catch (WebException ex) { Console.WriteLine(ex.Message); } finally { Console.Write("Press any key to continue..."); Console.ReadKey(false); } } private static CookieContainer GetLogonCookie() { // Create an instance of the loginWindows object. LoginWindowsDerived loginWindows = new LoginWindowsDerived(); loginWindows.EnforceWindowsAuth = true; loginWindows.Url = PROJECT_SERVER_URL + "LoginWindows.asmx"; loginWindows.Credentials = CredentialCache.DefaultCredentials; loginWindows.CookieContainer = new CookieContainer(); if (!loginWindows.Login()) { // Login failed; throw an exception. throw new UnauthorizedAccessException("Login failed."); } return loginWindows.CookieContainer; } } class ProjectInfo { private static SvcWssInterop.WssInterop wssInterop = new SvcWssInterop.WssInterop(); public String GetSiteInfo(Guid ProjectUID) { string prjSiteURL = "No Site Exists"; wssInterop.Credentials = CredentialCache.DefaultCredentials; SvcWssInterop.ProjectWSSInfoDataSet info = wssInterop.ReadWssData(ProjectUID); DataTable dt = info.ProjWssInfo; if (dt.Rows.Count > 0) { prjSiteURL = (string) dt.Rows[0]["PROJECT_WORKSPACE_URL"]; } return prjSiteURL; } } // Derive from LoginWindows class; include additional property and // override the web request header. class LoginWindowsDerived: SvcLoginWindows.LoginWindows { public bool EnforceWindowsAuth { get; set; } protected override WebRequest GetWebRequest(Uri uri) { WebRequest request = base.GetWebRequest(uri); if (this.EnforceWindowsAuth) { request.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f"); } return request; } } // Derive from Project class; include additional property and // override the web request header. class ProjectDerived: SvcProject.Project { public bool EnforceWindowsAuth { get; set; } protected override WebRequest GetWebRequest(Uri uri) { WebRequest request = base.GetWebRequest(uri); if (this.EnforceWindowsAuth) { request.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f"); } return request; } } }