Project.QueueCreateProjectAndCheckOut method

Creates a project with the specified entities and keeps the project checked out in the Drafts database.

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

Syntax

'Declaration
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Project/QueueCreateProjectAndCheckOut", RequestNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Project/",  _
    ResponseNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Project/",  _
    Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Sub QueueCreateProjectAndCheckOut ( _
    jobUid As Guid, _
    sessionUid As Guid, _
    sessionDescription As String, _
    dataset As ProjectDataSet, _
    validateOnly As Boolean _
)
'Usage
Dim instance As Project
Dim jobUid As Guid
Dim sessionUid As Guid
Dim sessionDescription As String
Dim dataset As ProjectDataSet
Dim validateOnly As Boolean

instance.QueueCreateProjectAndCheckOut(jobUid, _
    sessionUid, sessionDescription, _
    dataset, validateOnly)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Project/QueueCreateProjectAndCheckOut", RequestNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Project/", 
    ResponseNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Project/", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public void QueueCreateProjectAndCheckOut(
    Guid jobUid,
    Guid sessionUid,
    string sessionDescription,
    ProjectDataSet dataset,
    bool validateOnly
)

Parameters

  • sessionUid
    Type: System.Guid

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

  • sessionDescription
    Type: System.String

    The description of the session.

  • validateOnly
    Type: System.Boolean

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

Remarks

Use QueueCreateProjectAndCheckOut when you want to make additional changes to the project in this session. This saves a call to the server. If you do not want to make additional changes, use QueueCreateProject.

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

Note

Because the PSI does not support Claims authentication, the QueueCreateProjectAndCheckOut method does not support an enterprise project type (EPT) that uses a workflow definition for Windows Workflow Foundation 4 (WF4).

You can use the PSI to create projects with EPTs that either have no workflow or use a legacy WF3.5 definition. To create a project with an EPT that has a WF4 definition, use the CSOM.

The Project class methods, such as QueueCreateProjectAndCheckOut, 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.

You cannot use the Project Server Interface (PSI) to create local custom fields in projects. However, the PSI does support editing local custom field values on tasks, resources, and assignments.

When creating a ProjectDataSet.TaskRow, you must specify TASK_DUR_FMT. Otherwise, later use of this project in Project Professional can result in unpredictable behavior, including possible data loss.

Any changes made to enterprise resource properties in ProjectDataSet.ProjectResourceRow will be lost the next time Project Professional refreshes the data from Project Server.

When you add a task to a ProjectDataSet, 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.

Project Server Permissions

Permission

Description

NewProject

Allows a user to create a new global permission on the Project Server. Applies only to regular projects, not proposals.

OpenProject

Allows a user to open a project. Category permission. Applies only to projects that are created from an enterprise template and initiated by a project detail page (PDP).

SaveProject

Allows a user to save a project. Category permission. Applies only to projects that are initiated by a project detail page (PDP).

EditProjectProperties

Allows a user to edit a project. Category permission. Applies only to projects that are initiated by a project detail page (PDP).

Examples

The following example creates a project, saves it to the server but leaves it checked out, and then checks the project 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.QueueCreateProjectAndCheckOut
{
   class Program
   {
      [STAThread]
      static void Main(string[] args)
      {
         try
         {
            const string PROJECT_SERVER_URI = "https://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 utility";

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

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

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

            projectSvc.Url = PROJECT_SERVER_URI + PROJECT_SERVICE_PATH;
            projectSvc.Credentials = CredentialCache.DefaultCredentials;

            SvcQueueSystem.QueueSystem q = new SvcQueueSystem.QueueSystem();
            q.Url = PROJECT_SERVER_URI + QUEUESYSTEM_SERVICE_PATH;
            q.UseDefaultCredentials = true;

            // Create a sample project.
            Console.WriteLine("Creating project data");
            projectDs = new SvcProject.ProjectDataSet();

            // 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;
            projectDs.Project.AddProjectRow(projectRow);

            // Add some tasks.
            SvcProject.ProjectDataSet.TaskRow taskOne = projectDs.Task.NewTaskRow();
            taskOne.PROJ_UID = projectRow.PROJ_UID;
            taskOne.TASK_UID = Guid.NewGuid();
            taskOne.TASK_NAME = "Task One";
            taskOne.TASK_START_DATE = System.DateTime.Now.AddDays(1);
            projectDs.Task.AddTaskRow(taskOne);

            SvcProject.ProjectDataSet.TaskRow taskTwo = projectDs.Task.NewTaskRow();
            taskTwo.PROJ_UID = projectRow.PROJ_UID;
            taskTwo.TASK_UID = Guid.NewGuid();
            taskTwo.TASK_NAME = "Task Two";
            taskTwo.TASK_START_DATE = System.DateTime.Now.AddDays(1);
            projectDs.Task.AddTaskRow(taskTwo);

            // Save the project to the database.
            Console.WriteLine("Saving project data to the server and checking out");
            jobId = Guid.NewGuid();
            projectSvc.QueueCreateProjectAndCheckOut(jobId,sessionId,SESSION_DESC, projectDs, false);
            WaitForQueue(q, jobId);

            // Add your additional changes here.

            // Check in the project so that it is available for more changes.
            Console.WriteLine("Checking in the project");
            jobId = Guid.NewGuid();
            projectSvc.QueueCheckInProject(jobId,projectRow.PROJ_UID,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;
            Console.WriteLine(errMess);
         }
         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);
         }
         finally
         {
            Console.ResetColor();
            Console.WriteLine("\r\n\r\nPress any key...");
            Console.ReadKey();
         }
      }
      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.

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

            if (jobState == SvcQueueSystem.JobState.Success)
            {
               jobDone = true;
            }
            else
            {
               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));
               }
               else
               {
                  Console.WriteLine("Job State: " + jobState + " Job ID: " + jobId);
                  Thread.Sleep(QUEUE_WAIT_TIME * 1000);
               }
            }
         }
         while (!jobDone);
      }
   }
}

See also

Reference

Project class

Project members

WebSvcProject namespace