Creating a Project for a Department, and Using the WCF FaultException

When you add a Project Departments custom field to a ProjectDataSet.ProjectCustomFields table, do not set the value of the MD_PROP_ID property. Project Server automatically adds a value when it creates the project. The CreateProject4Department code example shows the data in the ProjectDataSet before and after the call to QueueCreateProject.

The WCF-based CreateProject4Department example in the attached file does the following:

  1. Builds a basic ProjectDataSet for one new project, including a row in the ProjectCustomFields table. The project is assigned to a specified department by using the Project Departments custom field that has a value in the Departments lookup table.

  2. After calling QueueCreateProject, waits for the project queue to finish, and then reads the ProjectDataSet back by using ReadProject.

  3. Saves the ProjectDataSet to XML files, once before creating the project and once after calling ReadProject. Shows that Project Server automatically creates the MD_PROP_ID field for the Project Departments custom field.

  4. Shows how to use the WCF FaultException, to display the error stack. Comments in the PopulateData method show how to create errors in the ProjectDataSet that trigger the System.ServiceModel.FaultException when you call QueueCreateProject.

To get a list of errors if you get a FaultException when you call a PSI method in a WCF-based application, you can extract a PSClientError object from the FaultException object. You can then use GetAllErrors to store the error information in a PSErrorInfo array and enumerate the errors.

In addition to the data in the PSClientError object, the FaultException object can include other types of errors, such as failure to connect to Project Server. The errOut parameter of the GetPSClientError method in the attached code sample shows additional information. When you make the changes that create errors in the ProjectCustomFields properties, and then run the application, the errOut parameter includes the errinfo element and other data (formatted here from the console output). Following is sample output from the exception handler:

Error details:
<errinfo xmlns=””>
  <dataset name=”ProjectDataSet”>
    <table name=”ProjectCustomFields”>
      <row CUSTOM_FIELD_UID=”976d3bd9-95ff-40a2-a938-960c410b0341″>
        <error id=”11704″ name=”CustomFieldInvalidTypeColumnFilledIn”
        <error id=”11713″ name=”CustomFieldRequiredValueNotProvided”

ProjectServerError(s) LastError=CustomFieldRequiredValueNotProvided Instructions:
Pass this into PSClientError constructor to access all error information
(Fault Detail is equal to SvcProject.ServerExecutionFault).

PSClientError output:

PSClientError output:

For information about using the attached WCF-based application in Visual Studio 2010, see Prerequisites for WCF-Based Code Samples in the SDK.

Comments (0)