Compartir a través de


ObjectLinkProvider.ReadTaskLinkedWebObjects Method

Gets a list of the linked Web objects for a specified task, filtered by object type.

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

Syntax

'Declaration
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/ObjectLinkProvider/ReadTaskLinkedWebObjects", RequestNamespace := "https://schemas.microsoft.com/office/project/server/webservices/ObjectLinkProvider/",  _
    ResponseNamespace := "https://schemas.microsoft.com/office/project/server/webservices/ObjectLinkProvider/",  _
    Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Function ReadTaskLinkedWebObjects ( _
    taskUid As Guid, _
    filterWebObjectTypes As Integer _
) As ObjectLinkProviderDataSet
'Usage
Dim instance As ObjectLinkProvider
Dim taskUid As Guid
Dim filterWebObjectTypes As Integer
Dim returnValue As ObjectLinkProviderDataSet

returnValue = instance.ReadTaskLinkedWebObjects(taskUid, _
    filterWebObjectTypes)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/ObjectLinkProvider/ReadTaskLinkedWebObjects", RequestNamespace = "https://schemas.microsoft.com/office/project/server/webservices/ObjectLinkProvider/", 
    ResponseNamespace = "https://schemas.microsoft.com/office/project/server/webservices/ObjectLinkProvider/", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public ObjectLinkProviderDataSet ReadTaskLinkedWebObjects(
    Guid taskUid,
    int filterWebObjectTypes
)

Parameters

  • filterWebObjectTypes
    Type: System.Int32
    Specifies the web object type.

Return Value

Type: [ObjectLinkProvider Web service].ObjectLinkProviderDataSet

Examples

The example uses the SvcObjectLinkProvider namespace in the ProjectServerServices.dll proxy assembly. The ConfigureClientEndPoints 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.

Note

This example is designed to demonstrate the use of the ReadTaskLinkedWebObjects method; it is not a full solution.

Before you run the sample application, perform the following steps:

  1. Use Project Professional 2010 to create and publish a project with at least one task.

  2. Use Project Web App to open the project site.

  3. Create at least one issue or risk in the Issue or Risk SharePoint list of the project site.

  4. Create web object links. For more information, see CreateWebObjectLinks

  5. Change the constructor values according to your example.

  6. Add a web service reference to https://localhost/pwa/_vti_bin/Lists.asmx, and name it WebSvcLists.

Here’s what this example does:

  • Verifies that the project and task exist and gets their corresponding GUIDs.

  • Get the SharePoint items linked to the specified task and writes the contents of the dsLinkedObjects DataSet, to the OLPDataset.xml file.

The sample XML file is as follows.

<?xml version="1.0" standalone="yes"?>
<ObjectLinkProviderDataSet xmlns="https://schemas.microsoft.com/office/project/server/webservices/ObjectLinkProviderDataSet/">
  <WebObjectLinks>
    <WOBJLINK_UID>a17480e7-0d2b-4480-a465-5fe7064eb0df</WOBJLINK_UID>
    <WOBJLINK_OBJECT1>7768c091-7956-4f3d-9c3f-078b9b038dda</WOBJLINK_OBJECT1>
    <WOBJLINK_OBJECT2>46cc14c8-8a3d-4421-873f-ea7bc9de353d</WOBJLINK_OBJECT2>
    <WOBJLINK_TYPE>1</WOBJLINK_TYPE>
    <CREATED_DATE>2010-10-20T10:13:44.66-07:00</CREATED_DATE>
    <MOD_DATE>2010-10-20T10:13:44.66-07:00</MOD_DATE>
  </WebObjectLinks>
  <WebObjects>
    <WOBJ_UID>46cc14c8-8a3d-4421-873f-ea7bc9de353d</WOBJ_UID>
    <WOBJ_TYPE>4</WOBJ_TYPE>
    <WOBJ_PROJ_UID>4f4b5ffb-e143-4c84-9cf4-299d316c7d8e</WOBJ_PROJ_UID>
    <WOBJ_TASK_UID>00000000-0000-0000-0000-000000000000</WOBJ_TASK_UID>
    <WOBJ_TP_ID>1</WOBJ_TP_ID>
    <WOBJ_LIST_NAME>8c6f74ee-3f64-4808-8e71-02d62c553374</WOBJ_LIST_NAME>
    <WOBJ_DESC />
    <WOBJ_DOC_REF_CNT>0</WOBJ_DOC_REF_CNT>
    <WOBJ_ISSUE_REF_CNT>0</WOBJ_ISSUE_REF_CNT>
    <WOBJ_OTHER_REF_CNT>2</WOBJ_OTHER_REF_CNT>
    <WOBJ_RISK_REF_CNT>0</WOBJ_RISK_REF_CNT>
    <WOBJ_SHARED_MILESTONE_REF_CNT>0</WOBJ_SHARED_MILESTONE_REF_CNT>
    <WOBJ_COMMITMENT_REF_CNT>0</WOBJ_COMMITMENT_REF_CNT>
    <CREATED_DATE>2010-10-18T10:41:27.777-07:00</CREATED_DATE>
    <MOD_DATE>2010-10-18T10:41:27.777-07:00</MOD_DATE>
  </WebObjects>
  <WebObjects>
    <WOBJ_UID>7768c091-7956-4f3d-9c3f-078b9b038dda</WOBJ_UID>
    <WOBJ_TYPE>2</WOBJ_TYPE>
    <WOBJ_PROJ_UID>4f4b5ffb-e143-4c84-9cf4-299d316c7d8e</WOBJ_PROJ_UID>
    <WOBJ_TASK_UID>42b0aa16-4936-45f9-b094-2e4975d2b6fd</WOBJ_TASK_UID>
    <WOBJ_TP_ID>-1</WOBJ_TP_ID>
    <WOBJ_LIST_NAME>00000000-0000-0000-0000-000000000000</WOBJ_LIST_NAME>
    <WOBJ_DESC />
    <WOBJ_DOC_REF_CNT>0</WOBJ_DOC_REF_CNT>
    <WOBJ_ISSUE_REF_CNT>1</WOBJ_ISSUE_REF_CNT>
    <WOBJ_OTHER_REF_CNT>0</WOBJ_OTHER_REF_CNT>
    <WOBJ_RISK_REF_CNT>0</WOBJ_RISK_REF_CNT>
    <WOBJ_SHARED_MILESTONE_REF_CNT>1</WOBJ_SHARED_MILESTONE_REF_CNT>
    <WOBJ_COMMITMENT_REF_CNT>0</WOBJ_COMMITMENT_REF_CNT>
    <CREATED_DATE>2010-10-20T10:13:44.62-07:00</CREATED_DATE>
    <MOD_DATE>2010-10-20T10:13:44.62-07:00</MOD_DATE>
  </WebObjects>
</ObjectLinkProviderDataSet>

The sample code is as follows.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.ServiceModel;
using System.Data;
using System.Xml;
using System.Web.Services;
using PSLibrary = Microsoft.Office.Project.Server.Library;

namespace Microsoft.SDK.Project.Samples.OLPRead
{
    class OLPRead
    {
        private static SvcProject.ProjectClient projectClient;
        private static SvcObjectLinkProvider.ObjectLinkProviderClient olpClient;
        private static string outFilePathOLPDataSet;

        private static string projectName;   // Name of the project.
        private static string taskName;      // Name of the task.
        private static string listName;      // Name of the SharePoint list.
        private static string linkedItems;   // List of linked items to be displayed.

        private static PSLibrary.WebObjectType webObjectType; // Type of web object (issue, risk, and so on.)

        private const string OUTPUT_FILES = @"C:\Projects\Samples\Output\";
        private const string ENDPOINT_P = "basicHttp_Project";
       // private const string ENDPOINT_WSS = "basicHttp_WssInterop";
        private const string ENDPOINT_OLP = "basicHttp_ObjectLinkProvider";

        public OLPRead()
        {
            // Constructor to assign values to the variables. 
            // Change these for your example.
            projectName = "My Swell Project2";
            taskName = "T2";
            listName = "Issues";
        }

        static void Main(string[] args)
        {
            // Configure the endpoints.
            bool configResult = false;
            configResult = ConfigClientEndpoints(ENDPOINT_P);
           // configResult = ConfigClientEndpoints(ENDPOINT_WSS);
            configResult = ConfigClientEndpoints(ENDPOINT_OLP);

            OLPRead param = new OLPRead();

            if (!configResult) throw new ApplicationException();

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

            // Set the output file path.
            outFilePathOLPDataSet = OUTPUT_FILES + "OLPDataSet.xml";

            Guid taskUid = new Guid();
            Guid projectUid = new Guid();
            String workspaceUrl = String.Empty;
           
            #region Verify input values.
            try
            {
                Console.WriteLine("Reading the list of projects...");

                // Check whether the project exists and get the project GUID.
                SvcProject.ProjectDataSet projectList = projectClient.ReadProjectList();
                foreach (DataRow projectRow in projectList.Project)
                {
                    if ((string)projectRow[projectList.Project.PROJ_NAMEColumn] == projectName)
                    {
                        projectUid = (Guid)projectRow[projectList.Project.PROJ_UIDColumn];
                        break;
                    }
                }
                if (projectUid == Guid.Empty)
                {
                    Console.WriteLine("Project not found: " + projectName + "\n");
                    throw new ApplicationException();
                }

                // Get the task UID for the specified task.
                Console.WriteLine("Reading the data for project: " + projectName);

                SvcProject.ProjectDataSet dsProject =
                    projectClient.ReadProject(projectUid, SvcProject.DataStoreEnum.PublishedStore);

                foreach (DataRow objRow in dsProject.Task)
                {
                    if ((string)objRow[dsProject.Task.TASK_NAMEColumn] == taskName)
                    {
                        taskUid = (Guid)objRow[dsProject.Task.TASK_UIDColumn];
                        break;
                    }
                }

                if (taskUid == Guid.Empty)
                {
                    Console.WriteLine("Task not found: " + taskName + "\n");
                    throw new ApplicationException();
                }

            }
            catch (FaultException fault)
            {
                // Use the WCF FaultException, because the ASMX SoapException does not 
                // exist in a WCF-based application.
                WriteFaultOutput(fault);
            }

            catch (CommunicationException e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(
                    "\n***System.ServiceModel.CommunicationException:");
                Console.WriteLine(e.ToString());
                Console.ResetColor();
            }

            catch (ApplicationException)
            {
                ExitApp();
            }
            #endregion


            #region Get the SharePoint items linked to the task
            // Get the OLP DataSet for all SharePoint items of specified type 
            // that are linked to the task.
            try
            {
                Console.WriteLine("\nGetting the list of SharePoint items linked to the task...");

                SvcObjectLinkProvider.ObjectLinkProviderDataSet dsLinkedObjects =
             new SvcObjectLinkProvider.ObjectLinkProviderDataSet();

                // Set the WebObjectType, based on the listName.
                switch (listName)
                {
                    case "Issues":
                        webObjectType = PSLibrary.WebObjectType.Issue;
                        break;
                    case "Risks":
                        webObjectType = PSLibrary.WebObjectType.Risk;
                        break;
                    case "Documents":
                        webObjectType = PSLibrary.WebObjectType.Document;
                        break;
                    case "Commitments":  // Commitments are now called Deliverables.
                        webObjectType = PSLibrary.WebObjectType.Commitment;
                        break;
                    default:
                        string errMess = listName +
                            " is not a default SharePoint list type for task links.";
                        throw new SystemException(errMess);
                }
                dsLinkedObjects = olpClient.ReadTaskLinkedWebObjects(taskUid,
                    (int)webObjectType);

                int itemsFound = 0;
                foreach (SvcObjectLinkProvider.ObjectLinkProviderDataSet.WebObjectsRow objRow
                    in dsLinkedObjects.WebObjects)
                {
                    if (objRow.WOBJ_TASK_UID != taskUid)
                    {
                        // Add the internal OLP GUID, List GUID, and TP_ID. 
                        linkedItems += string.Format(
                            "\n\n\tWebObjectUid:\t{0}\n\tList UID:\t{1}\n\tTP_ID:\t\t{2}",
                            objRow.WOBJ_UID.ToString(),
                            objRow.WOBJ_LIST_NAME,
                            objRow.WOBJ_TP_ID.ToString());
                        itemsFound++;
                    }
                }
                if (itemsFound == 0)
                {
                    linkedItems = "No " + listName.ToLower() + " found, for task: " + taskName;
                }
                else
                {
                    Console.WriteLine(linkedItems, listName);
                }
                
                
                // Write the OLP DataSet to an XML file.
                Console.WriteLine("\nWriting the OLP DataSet to an XML file...");
                dsLinkedObjects.WriteXml(outFilePathOLPDataSet);
                Console.WriteLine("\nSee XML output of OLP Dataset at {0}",
               outFilePathOLPDataSet);
                Console.Write("\nPress any key to continue: ");
                Console.ReadKey(true);
               
            }
            catch (FaultException fault)
            {
                // Use the WCF FaultException, because the ASMX SoapException does not 
                // exist in a WCF-based application.
                WriteFaultOutput(fault);
            }

            catch (CommunicationException e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(
                    "\n***System.ServiceModel.CommunicationException:");
                Console.WriteLine(e.ToString());
                Console.ResetColor();
            }
            #endregion
        }

        #region Private methods


        // Extract a PSClientError object from the WCF FaultException object, and
        // then display the exception details and each error in the PSClientError stack.
        private static void WriteFaultOutput(FaultException fault)
        {
            string errAttributeName;
            string errAttribute;
            string errOut;
            string errMess = "".PadRight(30, '=') + "\r\n"
                + "Error details: " + "\r\n";

            PSLibrary.PSClientError error = Helpers.GetPSClientError(fault, out errOut);
            errMess += errOut;

            if (error != null)
            {
                PSLibrary.PSErrorInfo[] errors = error.GetAllErrors();
                PSLibrary.PSErrorInfo thisError;

                for (int i = 0; i < errors.Length; i++)
                {
                    thisError = errors[i];
                    errMess += "\r\n".PadRight(30, '=') + "\r\nPSClientError output:\r\n";
                    errMess += thisError.ErrId.ToString() + "\n";

                    for (int j = 0; j < thisError.ErrorAttributes.Length; j++)
                    {
                        errAttributeName = thisError.ErrorAttributeNames()[j];
                        errAttribute = thisError.ErrorAttributes[j];
                        errMess += "\r\n\t" + errAttributeName
                            + ": " + errAttribute;
                    }
                }
            }
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(errMess);
            Console.ResetColor();
        }

        private static void ExitApp()
        {
            Console.Write("\nPress any key to exit: ");
            Console.ReadKey(true);
            Environment.Exit(0);
        }
        #endregion

        // Configure the PSI client endpoints.
        public static bool ConfigClientEndpoints(string endpt)
        {
            bool result = true;

            switch (endpt)
            {
                
                case ENDPOINT_P:
                    projectClient = new SvcProject.ProjectClient(endpt);
                    break;
                case ENDPOINT_OLP:
                    olpClient = new SvcObjectLinkProvider.ObjectLinkProviderClient(endpt);
                    break;
                default:
                    result = false;
                    Console.WriteLine("Invalid endpoint: {0}", endpt);
                    break;
            }
            return result;
        }

    }

    class Helpers
    {
        /// <summary>
        /// Extract a PSClientError object from the ServiceModel.FaultException,
        /// for use in output of the GetPSClientError stack of errors.
        /// </summary>
        /// <param name="e"></param>
        /// <param name="errOut">Shows that FaultException has more information 
        /// about the errors than PSClientError has. FaultException can also contain 
        /// other types of errors, such as failure to connect to the server.</param>
        /// <returns>PSClientError object, for enumerating errors.</returns>
        public static PSLibrary.PSClientError GetPSClientError(FaultException e,
                                                               out string errOut)
        {
            const string PREFIX = "GetPSClientError() returns null: ";
            errOut = string.Empty;
            PSLibrary.PSClientError psClientError = null;

            if (e == null)
            {
                errOut = PREFIX + "Null parameter (FaultException e) passed in.";
                psClientError = null;
            }
            else
            {
                // Get a ServiceModel.MessageFault object.
                var messageFault = e.CreateMessageFault();

                if (messageFault.HasDetail)
                {
                    using (var xmlReader = messageFault.GetReaderAtDetailContents())
                    {
                        var xml = new XmlDocument();
                        xml.Load(xmlReader);

                        var serverExecutionFault = xml["ServerExecutionFault"];
                        if (serverExecutionFault != null)
                        {
                            var exceptionDetails = serverExecutionFault["ExceptionDetails"];
                            if (exceptionDetails != null)
                            {
                                try
                                {
                                    errOut = exceptionDetails.InnerXml + "\r\n";
                                    psClientError =
                                        new PSLibrary.PSClientError(exceptionDetails.InnerXml);
                                }
                                catch (InvalidOperationException ex)
                                {
                                    errOut = PREFIX + "Unable to convert fault exception info ";
                                    errOut += "a valid Project Server error message. Message: \n\t";
                                    errOut += ex.Message;
                                    psClientError = null;
                                }
                            }
                            else
                            {
                                errOut = PREFIX + "The FaultException e is a ServerExecutionFault, "
                                    + "but does not have ExceptionDetails.";
                            }
                        }
                        else
                        {
                            errOut = PREFIX + "The FaultException e is not a ServerExecutionFault.";
                        }
                    }
                }
                else // No detail in the MessageFault.
                {
                    errOut = PREFIX + "The FaultException e does not have any detail.";
                }
            }
            errOut += "\r\n" + e.ToString() + "\r\n";
            return psClientError;
        }
    }

}

See Also

Reference

ObjectLinkProvider Class

ObjectLinkProvider Members

ObjectLinkProvider Web Service