Project.QueueAddToProject method

Office 2013 and later

Creates project entities that are specified in the ProjectDataSet by using an existing sessionUid for a checked-out project.

Namespace:  WebSvcProject
Assembly:  ProjectServerServices (in ProjectServerServices.dll)

[SoapDocumentMethodAttribute("", RequestNamespace = "", 
	ResponseNamespace = "", 
	Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public void QueueAddToProject(
	Guid jobUid,
	Guid sessionUid,
	ProjectDataSet dataset,
	bool validateOnly


Type: System.Guid

The GUID of the queue job.

Type: System.Guid

The GUID of the session in which the queue job is submitted.

Type: WebSvcProject.ProjectDataSet

Contains the project entities to create.

Type: System.Boolean

If True, only validates the input data and does not perform the action.

QueueAddToProject is an asynchronous method that sends a message to the Project Server Queuing Service.


When you create or update a project, the PSI can process up to 1000 rows of data at the same time. If the total number of rows of new or updated data in all tables of ProjectDataSet exceeds 1000, the PSI returns the ProjectExceededItemsLimit error.

When you add a task to a project by using the PSI, do not set the TASK_WBS property. The TASK_WBS property is read-only, although it is marked as read/write in the PSI. If you add a task with the TASK_WBS property set to a specified value, Project Professional ignores the value set from the PSI and assigns a value according to the task outline position when you open the project. To see the result in Project Professional, check the WBS code value on the Advanced tab of the Task Information dialog box.

QueueAddToProject cannot change a a null reference (Nothing in Visual Basic) task to a real task. For example, if you create tasks by using Project Professional and leave one or more empty lines between some of the tasks, the empty lines are a null reference (Nothing in Visual Basic) tasks.

The Project class methods, such as QueueAddToProject, cannot create, edit, or delete cost resources. If the ProjectDataSet in the dataset parameter includes a cost resource, the method returns the ResourceCannotCreateCostResource error 2076. You can use the CreateResources method to create cost resources, but Resource class methods cannot edit them. For more information, see What the PSI does and does not do.

Project Server Permissions




Allows a user to save the specified project. Category permission.

The following example creates a sample project to use, checks out the project, adds a new task to it, and checks the project back in.

For critical information about running this code sample, see Prerequisites for ASMX-based code samples in Project 2013.

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Web.Services.Protocols;
using System.Threading;
using PSLibrary = Microsoft.Office.Project.Server.Library;

namespace Microsoft.SDK.Project.Samples.QueueAddToProject
   class Program
      static void Main(string[] args)
            const string PROJECT_SERVER_URI = "http://ServerName/ProjectServerName/";
            const string PROJECT_SERVICE_PATH = "_vti_bin/psi/project.asmx";
            const string QUEUESYSTEM_SERVICE_PATH = "_vti_bin/psi/queuesystem.asmx";
            const string SESSION_DESC="Sample add to project utility";

            Guid sessionId = Guid.NewGuid();
            Guid jobId;
            Guid projectId;

            // Set up the web service objects.
            SvcProject.Project projectSvc = new SvcProject.Project();

            SvcProject.ProjectDataSet projectDs = new SvcProject.ProjectDataSet();

            projectSvc.Credentials = CredentialCache.DefaultCredentials;

            SvcQueueSystem.QueueSystem q = new SvcQueueSystem.QueueSystem();
            q.UseDefaultCredentials = true;

            // Create a sample project.
            Console.WriteLine("Creating Sample project");
            projectId = CreateSampleProject(projectSvc, q);
            Console.WriteLine("Created " + projectId.ToString());
            // Check out the project.
            Console.WriteLine("Checking out Sample project");
            projectSvc.CheckOutProject(projectId, sessionId, SESSION_DESC);

             *  Add some items to an existing, checked-out project.
            // Create a dataset to hold the new items.
            Console.WriteLine("Creating new data");
            SvcProject.ProjectDataSet newProjectData = new SvcProject.ProjectDataSet();
            // Add a new task.
            SvcProject.ProjectDataSet.TaskRow newTask = newProjectData.Task.NewTaskRow();
            newTask.PROJ_UID = projectId;
            newTask.TASK_UID = Guid.NewGuid();
            newTask.TASK_NAME = "An added Task";
            // Add to the project by using the current sessionID.
            Console.WriteLine("Adding new data");
            jobId = Guid.NewGuid();
            WaitForQueue(q, jobId);

            // Check in the project. 
            Console.WriteLine("Checking in the project");
            jobId = Guid.NewGuid();
            projectSvc.QueueCheckInProject(jobId, projectId, false, sessionId, SESSION_DESC);
            WaitForQueue(q, jobId);
         catch (SoapException ex)
            PSLibrary.PSClientError error = new PSLibrary.PSClientError(ex);
            PSLibrary.PSErrorInfo[] errors = error.GetAllErrors();
            string errMess = "==============================\r\nError: \r\n";
            for (int i = 0; i < errors.Length; i++)
               errMess += "\n" + ex.Message.ToString() + "\r\n";
               errMess += "".PadRight(30, '=') + "\r\nPSCLientError Output:\r\n \r\n";
               errMess += errors[i].ErrId.ToString() + "\n";

               for (int j = 0; j < errors[i].ErrorAttributes.Length; j++)
                  errMess += "\r\n\t" + errors[i].ErrorAttributeNames()[j] + ": " + errors[i].ErrorAttributes[j];
               errMess += "\r\n".PadRight(30, '=');
            Console.ForegroundColor = ConsoleColor.Red;
         catch (WebException ex)
            string errMess = ex.Message.ToString() +
               "\n\nLog on, or check the Project Server Queuing Service";
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Error: " + errMess);
         catch (Exception ex)
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Error: " + ex.Message);
            Console.WriteLine("\r\n\r\nPress any key...");
      static private void WaitForQueue(SvcQueueSystem.QueueSystem q, Guid jobId)
         SvcQueueSystem.JobState jobState;
         const int QUEUE_WAIT_TIME = 2; // two seconds
         bool jobDone = false;
         string xmlError = string.Empty;
         int wait = 0;

         // Wait for the project to get through the queue.
         // Get the estimated wait time in seconds.
         wait = q.GetJobWaitTime(jobId);

         // Wait for it.
         Thread.Sleep(wait * 1000);
         // Wait until it is finished.

            // Get the job state.
            jobState = q.GetJobCompletionState(jobId, out xmlError);

            if (jobState == SvcQueueSystem.JobState.Success)
               jobDone = true;
               if (jobState == SvcQueueSystem.JobState.Unknown
               || jobState == SvcQueueSystem.JobState.Failed
               || jobState == SvcQueueSystem.JobState.FailedNotBlocking
               || jobState == SvcQueueSystem.JobState.CorrelationBlocked
               || jobState == SvcQueueSystem.JobState.Canceled)
                  // If the job failed, error out.
                  throw (new ApplicationException("Queue request failed \"" + jobState + "\" Job ID: " + jobId + ".\r\n" + xmlError));
                  Console.WriteLine("Job State: " + jobState + " Job ID: " + jobId);
                  Thread.Sleep(QUEUE_WAIT_TIME * 1000);
         while (!jobDone);
      static private Guid CreateSampleProject(SvcProject.Project projectSvc, SvcQueueSystem.QueueSystem q)
         SvcProject.ProjectDataSet projectDs = new SvcProject.ProjectDataSet();
         Guid jobId;
         // Create the project.
         SvcProject.ProjectDataSet.ProjectRow projectRow = projectDs.Project.NewProjectRow();
         projectRow.PROJ_UID = Guid.NewGuid();
         projectRow.PROJ_NAME = "Its a wonderful project at " + 
            DateTime.Now.ToShortDateString().Replace("/", "") + " " + 
            DateTime.Now.ToShortTimeString().Replace(":", "");
         projectRow.PROJ_TYPE = (int)PSLibrary.Project.ProjectType.Project;

         // Add some tasks.
         SvcProject.ProjectDataSet.TaskRow taskOne = projectDs.Task.NewTaskRow();
         taskOne.PROJ_UID = projectRow.PROJ_UID;
         taskOne.TASK_UID = Guid.NewGuid();
         // The Task Duration format must be specified.
         taskOne.TASK_DUR_FMT = (int)PSLibrary.Task.DurationFormat.Day;
         taskOne.TASK_DUR = 4800;  // 8 hours in duration units (minute/10)
         taskOne.TASK_NAME = "Task One";
         taskOne.TASK_START_DATE = System.DateTime.Now.AddDays(1);

         SvcProject.ProjectDataSet.TaskRow taskTwo = projectDs.Task.NewTaskRow();
         taskTwo.PROJ_UID = projectRow.PROJ_UID;
         taskTwo.TASK_UID = Guid.NewGuid();
         // The Task Duration format must be specified.
         taskTwo.TASK_DUR_FMT = (int)PSLibrary.Task.DurationFormat.Day;
         taskTwo.TASK_DUR = 4800;  // 8 hours in duration units (minute/10)
         taskTwo.TASK_NAME = "Task Two";
         taskTwo.TASK_START_DATE = System.DateTime.Now.AddDays(1);

         // Save the project to the database.
         jobId = Guid.NewGuid();
         projectSvc.QueueCreateProject(jobId, projectDs, false);
         WaitForQueue(q, jobId);
         return projectRow.PROJ_UID;