ObjectLinkProvider.DeleteWebObjectLink Method

Deletes the link between two specified web objects.

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/DeleteWebObjectLink", 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 DeleteWebObjectLink ( _
    webObjectUid1 As Guid, _
    webObjectUid2 As Guid _
) As Integer
'Usage
Dim instance As ObjectLinkProvider
Dim webObjectUid1 As Guid
Dim webObjectUid2 As Guid
Dim returnValue As Integer

returnValue = instance.DeleteWebObjectLink(webObjectUid1, _
    webObjectUid2)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/ObjectLinkProvider/DeleteWebObjectLink", 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 int DeleteWebObjectLink(
    Guid webObjectUid1,
    Guid webObjectUid2
)

Parameters

  • webObjectUid1
    Type: System.Guid
    Contains the web object GUID.
  • webObjectUid2
    Type: System.Guid
    Contains the web object GUID.

Return Value

Type: System.Int32

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 demonstrates the use of the DeleteWebObjectLinks 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. Change the constructor values according to your example.

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

This example performs the following tasks:

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

  • Links a task and a SharePoint list item (in this case, an Issue).

  • Links a task and a generic object.

  • Gets the list of SharePoint items that are linked to a task and writes the contents of the ObjectLinkProvider dataSet dsLinkedObjects to an XML file.

  • Gets a list of generic items that are linked to a task.

  • Deletes the links to web objects.

For more information about how the sample code works, see Procedures 1-6 of How to: Use the OLP to Link an Object to a Task

The complete 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;
using WebSvcLists = Microsoft.SDK.Project.Samples.OLP.WebSvcLists;

namespace Microsoft.SDK.Project.Samples.OLP
{
    class OLP
    {
        private static SvcProject.ProjectClient projectClient;
        private static SvcWssInterop.WssInteropClient wssInteropClient;
        private static SvcObjectLinkProvider.ObjectLinkProviderClient olpClient;
        private static string outFilePathOLPDataSet;
        private static string outFilePathListItemsDS;
        private static string outFilePathGenericDS;
        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 listItemTitle; // Title of the SharePoint list item.
        private static PSLibrary.WebObjectType webObjectType; // Type of web object (issue, risk, and so on.)
        private static string linkedItems;   // List of linked items to be displayed.
        private static bool deleteLinks;     // Delete links after they are created.

        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 OLP()
        {
            // Constructor to assign values to the variables. 
            // Change these for your example.
            projectName = "My Swell Project2";
            taskName = "T2";
            listName = "Issues";
            listItemTitle = "Issue1";
            deleteLinks = false;
        }

        static void Main(string[] args)
        {
            // Configure the endpoints.
            bool configResult = false;
            configResult = ConfigClientEndpoints(ENDPOINT_P);
            configResult = ConfigClientEndpoints(ENDPOINT_WSS);
            configResult = ConfigClientEndpoints(ENDPOINT_OLP);
           
            OLP param = new OLP();
                     
            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";
            outFilePathListItemsDS = OUTPUT_FILES + "OLPListItemsDS.xml";
            outFilePathGenericDS = OUTPUT_FILES + "OLPGenericDS.xml";

            // Lists is a SharePoint web service.
            WebSvcLists.Lists wssLists = new WebSvcLists.Lists();
            wssLists.Credentials = System.Net.CredentialCache.DefaultCredentials;

            Guid taskUid = new Guid();
            Guid projectUid = new Guid();
            String worksiteUrl = String.Empty;
            int itemTPID = -1;
            Guid listUid = Guid.Empty;
            
            #region Verify input values.
            try
            {
                // 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);
                    Console.Read();
                }

                // Get a task UID for the specified task.
                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);
                    Console.Read();
                }

                // Set the worksite URL for the SharePoint Lists Web service.
                SvcWssInterop.ProjectWSSInfoDataSet dsProjectWssInfo = new SvcWssInterop.ProjectWSSInfoDataSet();
                dsProjectWssInfo = wssInteropClient.ReadWssData(projectUid);

                if (dsProjectWssInfo.ProjWssInfo.Count > 0)
                {
                    worksiteUrl = dsProjectWssInfo.ProjWssInfo[0].PROJECT_WORKSPACE_URL.ToString();
                    wssLists.Url = worksiteUrl + "/_vti_bin/lists.asmx";
                }
                else
                {
                    Console.WriteLine("Worksite not found for project: " + projectName);
                    Console.Read();
                }

                // Get the list GUID in the project worksite from the Lists Web service.
                listUid = GetListUid(wssLists, listName);
                if (listUid == Guid.Empty)
                {
                    Console.WriteLine("SharePoint list not found: " + listName);
                    Console.Read();
                }

                // Get the TP_ID for the specified SharePoint list item.
                itemTPID = GetItemTPID(wssLists, listItemTitle);
                if (itemTPID < 0)
                {
                   Console.WriteLine(string.Format("List {0} does not contain item: {1}",
                        listName, listItemTitle));
                }
            }
            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

            try
            {
                #region Link task and SharePoint list item
                // Get the task Web object, if there are any existing links to the task.
                Guid taskWebObjectUid = Guid.Empty;
                SvcObjectLinkProvider.ObjectLinkProviderDataSet dsLinkedObjects = 
                    new SvcObjectLinkProvider.ObjectLinkProviderDataSet();
                dsLinkedObjects = olpClient.ReadTaskWebObject(taskUid);
                int numTaskWebObjects = dsLinkedObjects.WebObjects.Count;

                if (numTaskWebObjects > 0)
                    taskWebObjectUid = dsLinkedObjects.WebObjects[0].WOBJ_UID;
                else
                {
                    Console.WriteLine(
                        "There are no linked Web objects for task: " + taskName);
                }

                // Create a Web object for the specified task.
                SvcObjectLinkProvider.ObjectLinkProviderDataSet dsTask =
                    new SvcObjectLinkProvider.ObjectLinkProviderDataSet();
                SvcObjectLinkProvider.ObjectLinkProviderDataSet.WebObjectsRow taskRow =
                    dsTask.WebObjects.NewWebObjectsRow();

                // Provide all known information to the Web object row for the task.  
                // If a task Web object does not exist, AddWebObjects creates
                // a new Web object and updates WOBJ_UID in taskRow.  
                taskRow.WOBJ_UID = taskWebObjectUid;
                taskRow.WOBJ_TASK_UID = taskUid;
                taskRow.WOBJ_PROJ_UID = projectUid;
                taskRow.WOBJ_TYPE = (int)PSLibrary.WebObjectDatabaseType.Task;
                dsTask.WebObjects.AddWebObjectsRow(taskRow);

                // Create a Web object for the list item, with the TP_ID of the list item.
                SvcObjectLinkProvider.ObjectLinkProviderDataSet dsListItems =
                    new SvcObjectLinkProvider.ObjectLinkProviderDataSet();
                SvcObjectLinkProvider.ObjectLinkProviderDataSet.WebObjectsRow listItemRow =
                    dsListItems.WebObjects.NewWebObjectsRow();

                // Provide all known information to the Web object row for the list item.  
                // If a list item Web object does not exist, AddWebObjects creates
                // a new Web object and updates WOBJ_UID in listItemRow.  
                listItemRow.WOBJ_UID = Guid.NewGuid();
                listItemRow.WOBJ_TP_ID = itemTPID;
                listItemRow.WOBJ_LIST_NAME = listUid;
                listItemRow.WOBJ_PROJ_UID = projectUid;

                switch (listName)
                {
                    case "Issues":
                        listItemRow.WOBJ_TYPE = 
                            (int)PSLibrary.WebObjectDatabaseType.Issue;
                        webObjectType = PSLibrary.WebObjectType.Issue;
                        linkedItems = "Issues found for task: " + taskName;
                        break;
                    case "Risks":
                        listItemRow.WOBJ_TYPE = 
                            (int)PSLibrary.WebObjectDatabaseType.Risk;
                        webObjectType = PSLibrary.WebObjectType.Risk;
                        linkedItems = "Risks found for task: " + taskName;
                        break;
                    case "Documents":
                        listItemRow.WOBJ_TYPE = 
                            (int)PSLibrary.WebObjectDatabaseType.Document;
                        webObjectType = PSLibrary.WebObjectType.Document;
                        linkedItems = "Documents found for task: " + taskName;
                        break;
                    case "Commitments":  // Commitments are now called Deliverables
                        listItemRow.WOBJ_TYPE = 
                            (int)PSLibrary.WebObjectDatabaseType.Commitment;
                        webObjectType = PSLibrary.WebObjectType.Commitment;
                        linkedItems = "Deliverables found for task: " + taskName;
                        break;
                    default:
                        string errMess = listName +
                            " is not a default SharePoint list type for task links.";
                        Console.WriteLine(errMess);
                        break;
                }
                dsListItems.WebObjects.AddWebObjectsRow(listItemRow);

                // You can link the task to multiple list items by adding multiple rows  
                // to dsListItems and adding ObjectLinkType values to the array of link types. 
                SvcObjectLinkProvider.WebObjectLinkType generalLinkType =
                    SvcObjectLinkProvider.WebObjectLinkType.General;
                SvcObjectLinkProvider.WebObjectLinkType[] wssLinkTypeArray = 
                { generalLinkType };

                olpClient.CreateWebObjectLinks(dsTask, dsListItems, wssLinkTypeArray);

                // Write the list items dataset to an XML file.
                dsListItems.WriteXml(outFilePathListItemsDS);
                Console.WriteLine("\nSee XML output of the list items Dataset at {0}",
                    outFilePathListItemsDS);
                Console.ReadKey();
                #endregion

                #region Link task and a generic object
                // Link a generic external item to the task. 
                // WOBJ_TP_ID is an arbitrary constant in this case, 
                // because the GUID is the important part for the link.
                int externalTPID = 1;

                // The external item must have a GUID; folowing is a sample GUID.
                Guid externalUid = new Guid("12345678-1234-1234-1234-123456789012");

                SvcObjectLinkProvider.ObjectLinkProviderDataSet dsGeneric =
                    new SvcObjectLinkProvider.ObjectLinkProviderDataSet();
                SvcObjectLinkProvider.ObjectLinkProviderDataSet.WebObjectsRow genericRow =
                    dsGeneric.WebObjects.NewWebObjectsRow();

                genericRow.WOBJ_UID = Guid.NewGuid();

                // Instead of a SharePoint list GUID, you can substitute any GUID here.  
                // If the object doesn't have a GUID, or you need to use the GUID and  
                // another ID, you can use the WOBJ_TP_ID field.
                genericRow.WOBJ_LIST_NAME = externalUid;
                genericRow.WOBJ_TP_ID = externalTPID;
                genericRow.WOBJ_PROJ_UID = projectUid;
                genericRow.WOBJ_TYPE =
                    (int)PSLibrary.WebObjectDatabaseType.GenericSharePointListItem;
                dsGeneric.WebObjects.AddWebObjectsRow(genericRow);

                // Create a new link type array for the generic link.
                SvcObjectLinkProvider.WebObjectLinkType[] genericLinkTypeArray = { generalLinkType };
                olpClient.CreateWebObjectLinks(dsTask, dsGeneric, genericLinkTypeArray);
                // Write the generic dataset to an XML file.
                dsGeneric.WriteXml(outFilePathGenericDS);
                Console.WriteLine("\nSee XML output of the Generic Dataset at {0}",
                    outFilePathGenericDS);
                Console.ReadKey();
                #endregion

                #region Get the list of SharePoint items linked to the task
                // Get the OLP DataSet for all SharePoint items of specified type 
                // that are linked to the task.
                dsLinkedObjects = olpClient.ReadTaskLinkedWebObjects(taskUid,
                    (int)webObjectType);

                // Write the OLP DataSet to an XML file.
                dsLinkedObjects.WriteXml(outFilePathOLPDataSet);
                Console.WriteLine("\nSee XML output of OLP Dataset at {0}",
               outFilePathOLPDataSet);
                Console.ReadKey();

                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\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;
                Console.WriteLine(linkedItems, listName);
                #endregion

                #region Get list of generic items linked to the task
                // Get the OLP DataSet for all generic items linked to the task.
                dsLinkedObjects = olpClient.ReadTaskLinkedWebObjects(taskUid,
                    (int)PSLibrary.WebObjectType.GenericSharePointListItem);

                linkedItems = "Generic items found:";

                itemsFound = 0;
                foreach (SvcObjectLinkProvider.ObjectLinkProviderDataSet.WebObjectsRow objRow in
                    dsLinkedObjects.WebObjects)
                {
                    if (objRow.WOBJ_TASK_UID != taskUid)
                    {
                        linkedItems += string.Format(
                           "\n\n\tWebObjectUid:\t{0}\n\tExternal UID:\t{1}\n\tFake TP_ID:\t{2}",
                           objRow.WOBJ_UID.ToString(),
                           objRow.WOBJ_LIST_NAME,
                           objRow.WOBJ_TP_ID.ToString());
                        itemsFound++;
                    }
                }
                if (itemsFound == 0)
                    linkedItems = "No generic items found for task: " + taskName;
                Console.WriteLine(linkedItems, "Generic Linked Items");
                Console.Read();
                #endregion

                #region Delete the links
                if (deleteLinks)
                {
                    int[] deletedItems = { 0, 0 };

                    // Delete the link from the task to the SharePoint list item.
                    deletedItems[0] = DeleteTaskLinks(olpClient, taskUid, listUid, itemTPID);

                    // Delete the link from the task to the generic item.
                    deletedItems[1] = DeleteTaskLinks(olpClient, taskUid, externalUid, externalTPID);

                    string deletedResults = "For task: " + taskName + "\n\n";
                    deletedResults += "Deleted SharePoint list items: ";
                    deletedResults +=
                        string.Format("{0}\n\nDeleted generic items: {1}",
                            deletedItems[0].ToString(), deletedItems[1].ToString());
                    Console.WriteLine(deletedResults, "Deleted Links");
                }
                #endregion
            }
            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();
            }
            
        }

        #region Private methods
        private static Guid GetListUid(WebSvcLists.Lists wssLists, string listName)
        {
            const string idAttribute = "ID";
            const string defaultViewUrl = "DefaultViewUrl";
            string listNodeName = "/" + listName + "/";
            Guid listUid = Guid.Empty;

            XmlNode ndLists = wssLists.GetListCollection();

            // Get the GUID for the specified SharePoint list.  
            foreach (XmlNode ndList in ndLists.ChildNodes)
            {
                if (ndList.Attributes[defaultViewUrl].Value.Contains(listNodeName))
                {
                    listUid = new Guid(ndList.Attributes[idAttribute].Value);
                    break;
                }
            }
            return listUid;
        }

        private static int GetItemTPID(WebSvcLists.Lists wssLists, string listItemTitle)
        {

            int itemTPID = -1;
            XmlDocument xmlDoc = new XmlDocument();
            XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");
            // Query for the list item title.
            string queryFormat =
                "<Where><Eq><FieldRef Name='Title'/><Value Type='Text'>{0}</Value></Eq></Where>";
            ndQuery.InnerXml = string.Format(queryFormat, listItemTitle);

            XmlNode ndQueryOptions = xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", "");
            ndQueryOptions.InnerXml = "<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns>" +
                "<DateInUtc>TRUE</DateInUtc>";

            // Get the Title and ID fields in the returned data.
            XmlNode ndViewFields = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", "");
            ndViewFields.InnerXml = "<FieldRef Name='Title' /><FieldRef Name='ID'/>";

            string viewName = string.Empty;
            string webId = string.Empty;
            string rowLimit = string.Empty;

            // GetListItems returns <listitems> element with the child <rs:data ItemCount="1">,
            // which contains the following <z:row> child element: 
            //     <z:row ows_Title="Test Issue 1" ows_ID="1" ...[additional metadata] /> 
            // The TP_ID is in the ows_ID attribute, so we can jump to that row. 
            try
            {
                XmlNode ndListItems = wssLists.GetListItems(listName, viewName, ndQuery, ndViewFields,
                                                         rowLimit, ndQueryOptions, webId);
                if (ndListItems.ChildNodes.Count > 1
                && ndListItems.ChildNodes[1].ChildNodes.Count > 1)
                {
                    string tpidValue = "-1";
                    tpidValue = ndListItems.ChildNodes[1].ChildNodes[1].Attributes["ows_ID"].Value;
                    itemTPID = Convert.ToInt16(tpidValue);
                }
            }

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

        private static int DeleteTaskLinks(SvcObjectLinkProvider.ObjectLinkProvider olp,
            Guid taskUid, Guid objectUid, int itemTPID)
        {
            int deleteResult;
            SvcObjectLinkProvider.ObjectLinkProviderDataSet dsDeleteTask =
                olp.ReadTaskWebObject(taskUid);
            Guid delTaskUid = dsDeleteTask.WebObjects[0].WOBJ_UID;

            SvcObjectLinkProvider.ObjectLinkProviderDataSet dsDeleteItem =
                olp.ReadSharePointWebObject(itemTPID, objectUid);
            Guid delItemUid = dsDeleteItem.WebObjects[0].WOBJ_UID;

            deleteResult = olp.DeleteWebObjectLink(delTaskUid, delItemUid);
            return deleteResult;
        }

        // 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();
        }
        #endregion

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

            switch (endpt)
            {
                case ENDPOINT_WSS:
                    wssInteropClient = new SvcWssInterop.WssInteropClient(endpt);
                    break;
                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