
March 10, 2009 08:22 by
Simon
Integrating with project server is as simple as adding a number of web references and calling the right web methods. For more information on the web services available, consult the SDK.
The code below shows how to create a new draft project in project server after authenticating. The first thing I did was to add web references to the project and windows login web services - http://<server-name>/<project-server-name>/_vti_bin/psi/Project.asmx and http://<server-name>/<project-server-name>/_vti_bin/psi/LoginWindows.asmx respectively (the default project server name is pwa).
private string baseUrl = "http://portal.sharpcoder.co.uk/pwa/";
private const string LOGINWINDOWS = "_vti_bin/PSI/LoginWindows.asmx";
private const string PROJECTWEBSERVICE = "_vti_bin/PSI/Project.asmx";
private void CreateProject(string username,
string password,
string domain,
string projectName)
{
CredentialCache cache = new CredentialCache();
cache.Add(new Uri(baseUrl), "NTLM", new NetworkCredential(username, password, domain));
// WebSvcLoginWindows and WebSvcProject are the names given to the web references
WebSvcLoginWindows.LoginWindows login = new WebSvcLoginWindows.LoginWindows();
WebSvcProject.Project project = new WebSvcProject.Project();
// Set up login web service and login using windows authentication
login.Url = baseUrl + LOGINWINDOWS;
login.Credentials = cache;
login.Login();
// Set up the project web service
project.Url = baseUrl + PROJECTWEBSERVICE;
project.Credentials = cache;
// Create a project data set for the new project
WebSvcProject.ProjectDataSet dsProject = new WebSvcProject.ProjectDataSet();
WebSvcProject.ProjectDataSet.ProjectRow projectRow = dsProject.Project.NewProjectRow();
// Probably want to record the guid of the new project in a database or something
Guid projectGuid = Guid.NewGuid();
projectRow.PROJ_UID = projectGuid;
projectRow.PROJ_NAME = job.Title;
dsProject.Project.AddProjectRow(projectRow);
project.QueueCreateProject(Guid.NewGuid(), dsProject, false);
}
6603fb46-de90-4a28-a25c-d66fe4937eaf|0|.0