Partager via


Workflow.ReadWorkflowStageList Method

Reads the list of workflow stages.

Namespace:  [Workflow Web service]
Service reference: http://ServerName:32843/[Project Service Application GUID]/PSI/Workflow.svc
Web service reference: http://ServerName/ProjectServerName/_vti_bin/PSI/Workflow.asmx?wsdl

Syntax

'Declaration
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Workflow/ReadWorkflowStageList", RequestNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Workflow/",  _
    ResponseNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Workflow/",  _
    Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Function ReadWorkflowStageList As WorkflowDataSet
'Usage
Dim instance As Workflow
Dim returnValue As WorkflowDataSet

returnValue = instance.ReadWorkflowStageList()
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Workflow/ReadWorkflowStageList", RequestNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Workflow/", 
    ResponseNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Workflow/", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public WorkflowDataSet ReadWorkflowStageList()

Return Value

Type: [Workflow Web service].WorkflowDataSet

Remarks

Each WorkflowDataSet.WorkflowStageRow in the WorkflowDataSet.WorkflowStageDataTable contains the information for one stage.

Project Server Permissions

Permission

Description

ManageWorkflow

Allows the user to manage workflows. Global permission.

Examples

The example uses the SvcWorkflow namespace in the ProjectServerServices.dll proxy assembly. The ConfigClientEndpoints method uses an app.config file for setting the WCF binding, behavior, and endpoint. For information about creating a PSI proxy assembly and an app.config file, see Prerequisites for WCF-Based Code Samples.

The following example uses ReadWorkflowStageList to read the existing stages of a workflow. The resulting dataset, workflowDS, contains all the phases and stages in a workflow, and is written to the WorkflowStageList.xml file. Following is part of the WorkflowStageList.xml file.

<?xml version="1.0" standalone="yes"?>
<WorkflowDataSet xmlns="https://schemas.microsoft.com/office/project/server/webservices/WorkflowDataSet/">
<WorkflowPhase>
<PHASE_UID>d8bc257b-c2ec-4186-8a5b-44b5b7f21d82</PHASE_UID>
<PHASE_NAME>Create</PHASE_NAME>
<PHASE_DESCRIPTION>Project information is captured in this phase</PHASE_DESCRIPTION>
</WorkflowPhase> 
<WorkflowStage>
<STAGE_UID>a8a158d1-a9b9-41d7-a676-d199118221c7</STAGE_UID>
<STAGE_NAME>TestStage</STAGE_NAME>
<PHASE_UID>d8bc257b-c2ec-4186-8a5b-44b5b7f21d82</PHASE_UID>
<PHASE_NAME>Create</PHASE_NAME>
<STAGE_DESCRIPTION>a test stage</STAGE_DESCRIPTION>
<CHECKIN_REQUIRED>false</CHECKIN_REQUIRED>
<STAGE_SUBMIT_DESCRIPTION />
<STATUS_PDP_UID>a7aa1c62-9577-447c-823e-bdb161f9000d</STATUS_PDP_UID>
</WorkflowStage>

Following is the complete sample code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.ServiceModel;

namespace Microsoft.SDK.Project.Samples.WorkFlowTest
{
    class WorkFlowProject
    {
        private static SvcWorkflow.WorkflowClient workFlowClient;
        private const string WORK_ENDPOINT = "basicHttp_Workflow";
        private const string OUTPUT_FILES = @"C:\Projects\Samples\Output\";
        private static string outFilePathWorkFlowStageList;
        private static string outFilePathNewWorkFlowStage;
        private static string outFilePathStageInfo;
        private static string outFilePathUpdatedStage;

        static void Main(string[] args)
        {
            // Configure client endpoints.
            ConfigClientEndpoints(WORK_ENDPOINT);

            Guid[] workFlowID = new Guid[1];
            workFlowID[0] = new Guid("e663d9dc-f78d-4a4e-ac21-b28d22865f58");

            // If output directory does not exist, create it.
            if (!Directory.Exists(OUTPUT_FILES))
            {
                Directory.CreateDirectory(OUTPUT_FILES);
            }

            outFilePathWorkFlowStageList = OUTPUT_FILES + "WorkFlowStageList.xml";
            outFilePathNewWorkFlowStage = OUTPUT_FILES + "NewWorkflowStageInfo.xml";
            outFilePathStageInfo = OUTPUT_FILES + "StageInfo.xml";
            outFilePathUpdatedStage = OUTPUT_FILES + "UpdatedStage.xml";

            // Create a workflow dataset.
            SvcWorkflow.WorkflowDataSet workFlowDS = new SvcWorkflow.WorkflowDataSet();

            // List the workflow stages.
            workFlowDS = ListWorkflowStages(workFlowDS);

            // Create a new workflow stage.
            CreateWorkflowStageTest(workFlowDS);

            // Get workflow stage properties for a given stage.
            GetStageInfo();
        }
                
        // Read and display the properties of a stage, given the stage GUID.
        private static void GetStageInfo()
        {
            SvcWorkflow.WorkflowDataSet stageInfoDS = new SvcWorkflow.WorkflowDataSet();
            string stageName = "TestStage10";
            
            Guid stageGuid1 = new Guid("a8a158d1-a9b9-41d7-a676-d199118221c7");
            stageInfoDS = workFlowClient.ReadWorkflowStage(stageGuid1);

            Console.WriteLine("\nSee XML output of the WorkFlowDataSet at {0}",
               outFilePathStageInfo);

            // Update the stage  name.
            UpdateStage(stageInfoDS, stageName, stageGuid1);

            // Get the updated stage info.
            stageInfoDS = workFlowClient.ReadWorkflowStage(stageGuid1);
            stageInfoDS.WriteXml(outFilePathStageInfo);
            Console.ReadKey();
        }
               
        // Update the stage name.
        private static void UpdateStage(SvcWorkflow.WorkflowDataSet stageInfoDS, string stageName, Guid stageGuid1)
        {
            SvcWorkflow.WorkflowDataSet.WorkflowStageRow sRow;
            sRow = stageInfoDS.WorkflowStage.FindBySTAGE_UID(stageGuid1);
            sRow.STAGE_NAME = stageName;
            Console.WriteLine("Updating the stage name........");

            workFlowClient.UpdateWorkflowStage(stageInfoDS);

            // Write the updated stage info to an xml file.
            stageInfoDS.WriteXml(outFilePathUpdatedStage);
            Console.WriteLine("Stage name updated!");
            Console.WriteLine("\nSee XML output of the Updated WorkFlowDataSet at {0}",
            outFilePathUpdatedStage);
        }

        // Create a workflow stage.
        private static void CreateWorkflowStageTest(SvcWorkflow.WorkflowDataSet workFlowDS)
        {
            // The GUID of the Create phase.
            Guid phaseGuid = new Guid("d8bc257b-c2ec-4186-8a5b-44b5b7f21d82 ");  

            Guid statusPDPId = new Guid("A7AA1C62-9577-447C-823E-BDB161F9000D");
            Guid pdp_uid = new Guid("659FF164-1297-4B64-B813-489566774E27");
            Guid stageUid = Guid.NewGuid();
                       
            // Create a workflow stage row.
            SvcWorkflow.WorkflowDataSet.WorkflowStageRow workflowstageRow = 
                workFlowDS.WorkflowStage.NewWorkflowStageRow();
            workflowstageRow.STAGE_NAME = "Test Stage 5";
            workflowstageRow.STAGE_DESCRIPTION = "Adding a test stage row";
            workflowstageRow.PHASE_NAME = "Create";
            workflowstageRow.PHASE_UID = phaseGuid;
            workflowstageRow.CHECKIN_REQUIRED = false;
            workflowstageRow.STAGE_UID = stageUid;
            workflowstageRow.STATUS_PDP_UID = statusPDPId;
            workFlowDS.WorkflowStage.AddWorkflowStageRow(workflowstageRow);

            // Add a project details page for the Stage created above.
            SvcWorkflow.WorkflowDataSet.WorkflowStagePDPsRow pdpRow = 
                workFlowDS.WorkflowStagePDPs.NewWorkflowStagePDPsRow();
            pdpRow.STAGE_UID = stageUid;
            pdpRow.PDP_UID = pdp_uid;
            pdpRow.PDP_NAME = "Project Information";
            pdpRow.PDP_POSITION = 0;
            pdpRow.PDP_ID = 4;
            pdpRow.PDP_REQUIRES_ATTENTION = false;
            workFlowDS.WorkflowStagePDPs.AddWorkflowStagePDPsRow(pdpRow);
        
            // Create the stage.
            workFlowClient.CreateWorkflowStage(workFlowDS);
            
            // Write the dataset with the new Stage to an xml file.
            workFlowDS.WriteXml(outFilePathNewWorkFlowStage);
            Console.WriteLine("\nSee XML output of the WorkFlowDataSet at {0}",
               outFilePathNewWorkFlowStage);
        }

        // List the workflow stages in the dataset.
        private static SvcWorkflow.WorkflowDataSet ListWorkflowStages(SvcWorkflow.WorkflowDataSet workFlowDS)
        {
            workFlowDS = workFlowClient.ReadWorkflowStageList();
            workFlowDS.WriteXml(outFilePathWorkFlowStageList);

            Console.WriteLine("\nSee XML output of the WorkFlowDataSet at {0}",
               outFilePathWorkFlowStageList);
            return workFlowDS;
        }

        // Configure the custom field client endpoints.
        public static void ConfigClientEndpoints(string endpt)
        {
             workFlowClient = new SvcWorkflow.WorkflowClient(endpt);
           
        }
    }
}

See Also

Reference

Workflow Class

Workflow Members

Workflow Web Service