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 CreateProject4Department.zip file does the following:
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.
After calling QueueCreateProject, waits for the project queue to finish, and then reads the ProjectDataSet back by using ReadProject.
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.
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 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 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).
For information about using the attached WCF-based application in Visual Studio 2010, see Prerequisites for WCF-Based Code Samples in the SDK.