Hi
I am creating a timesheet programmatically using 2010 PWA services, every thing work fine except while executing the CreateTimeSheet method i am getting the following error.
ProjectServerError(s) LastError=GeneralInvalidOperation Instructions: Pass this into PSClientError constructor to access all error information.
Passing this to PSClientError not get enough information about the actual errro.
Can anybody help me out in this problem, I am not getting any clue about this
using System;using System.Collections.Generic;using System.Text;using System.Net;using System.Data;using System.Web.Services.Protocols;using PSLibrary = Microsoft.Office.Project.Server.Library;using SvcProject;using SvcResource;using SvcTimeSheet;using SvcAdmin;using SvcQueueSystem;namespace SampleTimeSheetDemo {class Program {staticvoid Main(string[] args) {try {#region Setup//const string PROJECT_SERVER_URI = "http:// ServerName/ProjectServerName/"; // <<--Change to be the name of your server running Project Server and the name of your directory.//const string TIMESHEET_SERVICE_PATH = "_vti_bin/psi/timesheet.asmx";//const string RESOURCE_SERVICE_PATH = "_vti_bin/psi/resource.asmx";//const string ADMIN_SERVICE_PATH = "_vti_bin/psi/admin.asmx"; TimesheetDataSet timesheetDs;// Set up the services. TimeSheetClient timeSheetSvc = new TimeSheetClient("basicHttp_TimeSheet"); ResourceClient resourceSvc = new ResourceClient("basicHttp_Resource"); AdminClient adminSvc = new AdminClient("basicHttp_Admin");//TimeSheetWebSvc.TimeSheet timeSheetSvc = new TimeSheetWebSvc.TimeSheet();//timeSheetSvc.UseDefaultCredentials = true;//timeSheetSvc.Url = PROJECT_SERVER_URI + TIMESHEET_SERVICE_PATH;//ResourceWebSvc.Resource resourceSvc = new ResourceWebSvc.Resource();//resourceSvc.Url = PROJECT_SERVER_URI + RESOURCE_SERVICE_PATH;//resourceSvc.UseDefaultCredentials = true;//AdminWebSvc.Admin adminSvc = new AdminWebSvc.Admin();//adminSvc.Url = PROJECT_SERVER_URI + ADMIN_SERVICE_PATH;//adminSvc.UseDefaultCredentials = true; Guid myUid = resourceSvc.GetCurrentUserUid(); #endregion#region Read Timesheet// Time periods must be created by the admin to use timesheets.// We are just reading the first open period here. TimePeriodDataSet timeperiodDs = adminSvc.ReadPeriods(PeriodState.Open); Guid periodUid = new Guid(timeperiodDs.TimePeriods.Select("[WPRD_NAME] = '2011Period-3'")[0]["WPRD_UID"].ToString()); //timeperiodDs.TimePeriods[0].WPRD_UID;//2011Period-14// If the timesheet already exists, read it.// (To delete an existing unsubmitted timesheet,// go to the My Timesheet area of the Project Web App site.) timesheetDs = timeSheetSvc.ReadTimesheetByPeriod(myUid, periodUid, Navigation.Current);#endregion#region CreateTimesheet if it doesn't exist, then read it// If the timesheet does not exist, create it.if (timesheetDs.Headers.Count < 1) { timesheetDs = new TimesheetDataSet(); TimesheetDataSet.HeadersRow headersRow = timesheetDs.Headers.NewHeadersRow(); headersRow.RES_UID = myUid; headersRow.TS_UID = Guid.NewGuid(); headersRow.WPRD_UID = periodUid; headersRow.TS_CREATOR_RES_UID = myUid; headersRow.TS_NAME = "Timesheet "; headersRow.TS_COMMENTS = "Random comment text here"; headersRow.TS_ENTRY_MODE_ENUM = (byte)PSLibrary.TimesheetEnum.EntryMode.Daily; timesheetDs.Headers.AddHeadersRow(headersRow);// Create the timesheet with the default line types that are specified by the admin. timeSheetSvc.CreateTimesheet(timesheetDs, PreloadType.Default); timesheetDs = timeSheetSvc.ReadTimesheet(headersRow.TS_UID); } CodeSampleUtilities.WriteTablesFormated("Timesheet after create:", timesheetDs.Tables);#endregion }catch (SoapException ex) { ExceptionHandlers.HandleSoapException(ex); }catch (WebException ex) { ExceptionHandlers.HandleWebException(ex); }catch (Exception ex) { ExceptionHandlers.HandleException(ex); }finally { ExceptionHandlers.ResetConsole(); } } }class ExceptionHandlers {publicstaticvoid HandleSoapException(SoapException ex) { PSLibrary.PSClientError error = new PSLibrary.PSClientError(ex); PSLibrary.PSErrorInfo[] errors = error.GetAllErrors();string errMess = "==============================\r\nError: \r\n";for (int i = 0; i < errors.Length; i++) { errMess += "\n"+ ex.Message.ToString() + "\r\n"; errMess += "".PadRight(30, '=') + "\r\nPSCLientError Output:\r\n \r\n"; errMess += errors[i].ErrId.ToString() + "\n";for (int j = 0; j < errors[i].ErrorAttributes.Length; j++) { errMess += "\r\n\t"+ errors[i].ErrorAttributeNames()[j] + ": "+ errors[i].ErrorAttributes[j]; } errMess += "\r\n".PadRight(30, '='); } Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(errMess); }publicstaticvoid HandleWebException(WebException ex) {string errMess = ex.Message.ToString() +"\n\nLog on, or check the Project Server Queuing Service"; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Error: "+ errMess); }publicstaticvoid HandleException(Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Error: "+ ex.Message); }publicstaticvoid ResetConsole() { Console.ResetColor(); Console.WriteLine("\r\n\r\nPress any key..."); Console.ReadKey(); } }class CodeSampleUtilities {// Write all contents of a table collection to the console.publicstaticvoid WriteTablesToConsole(System.Data.DataTableCollection theTables) { Console.ForegroundColor = ConsoleColor.DarkGreen;foreach (System.Data.DataTable table in theTables) {int[] columnWidths = newint[table.Columns.Count];int tableWidth = 0;string dataString; Console.WriteLine("Table: "+ table.TableName);// Write out the column names and get their spacing. StringBuilder tableRow = new StringBuilder();for (int i = 0; i < table.Columns.Count; i++) { columnWidths[i] = GetColumnWidth(table.Columns[i]); tableRow.Append(table.Columns[i].ColumnName.PadRight(columnWidths[i])); tableWidth += columnWidths[i]; }// Add a space so that it will not wrap. tableWidth += 1;// Make the console as wide as the widest table. Console.BufferWidth = (Console.BufferWidth > tableWidth ? Console.BufferWidth : tableWidth); tableRow.Append("\r\n"); Console.Write(tableRow.ToString());// Write out the data.foreach (DataRow row in table.Rows) { tableRow = new StringBuilder();for (int i = 0; i < table.Columns.Count; i++) { dataString = row[i].ToString(); // Truncate output if it is wider than // the desired column width.if (dataString.Length >= columnWidths[i]) { dataString = dataString.Substring(0, columnWidths[i] - 1); }// Add the output to the stringbuilder and pad right to fill// up to the column width. tableRow.Append(dataString.PadRight(columnWidths[i])); } tableRow.Append("\r\n"); Console.Write(tableRow.ToString()); } Console.Write("\r\n".PadLeft(tableWidth, '-')); } Console.ResetColor(); }// A helper function for WriteTablesToConsole.privatestaticint GetColumnWidth(DataColumn column) {// Note: Might not handle byte[]data types well.constint MAX_COL_WIDTH = 40;int dataWidth = 0;//Return 12 for numbers, 30 for dates, and string width for strings.switch (column.DataType.UnderlyingSystemType.ToString()) {case"System.Boolean":case"System.Byte":case"System.Byte[]":case"System.Char":case"System.Decimal":case"System.Double":case"System.Int16":case"System.Int32":case"System.Int64":case"System.SByte":case"System.Single":case"System.UInt16":case"System.UInt32":case"System.UInt64": dataWidth = 12;break;case"System.DateTime":case"System.TimeSpan": dataWidth = 30;break;case"System.Guid": dataWidth = 37;break;case"System.String":// If it has a maxlength, use it.if (column.MaxLength > 0) { dataWidth = column.MaxLength; }else {// Otherwise use the max col width. dataWidth = MAX_COL_WIDTH; }break;default: dataWidth = column.ColumnName.Length;break; }// Truncate if over the maxlength.if (dataWidth > MAX_COL_WIDTH) { dataWidth = MAX_COL_WIDTH; }// Always be at least as wide as the colum name.return (column.ColumnName.Length > (dataWidth) ? column.ColumnName.Length + 1 : dataWidth); }publicstaticvoid WriteTablesFormated(string Title, System.Data.DataTableCollection theTables) { WriteSeparator(); Console.WriteLine(Title); CodeSampleUtilities.WriteTablesToConsole(theTables); } publicstaticvoid WriteSeparator() { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine("".PadRight(Console.BufferWidth, '=')); Console.ResetColor(); } } }
and my app.config file
<?xmlversion="1.0"?><configuration><startup><supportedRuntimeversion="v2.0.50727"/></startup><system.serviceModel><behaviors><endpointBehaviors><behaviorname="basicHttpBehavior"><clientCredentials><windowsallowedImpersonationLevel="Impersonation"/></clientCredentials></behavior></endpointBehaviors></behaviors><bindings><basicHttpBinding><bindingname="basicHttpConf"sendTimeout="01:00:00"maxBufferSize="500000000"maxReceivedMessageSize="500000000"><readerQuotasmaxDepth="32"maxStringContentLength="8192"maxArrayLength="16384"maxBytesPerRead="4096"maxNameTableCharCount="500000000"/><securitymode="TransportCredentialOnly"><transportclientCredentialType="Ntlm"realm="http"/></security></binding></basicHttpBinding></bindings><client><endpointaddress="http://asproject/ConsultingTest/_vti_bin/PSI/ProjectServer.svc"behaviorConfiguration="basicHttpBehavior"binding="basicHttpBinding"bindingConfiguration="basicHttpConf"contract="SvcResource.Resource"name="basicHttp_Resource"/><endpointaddress="http://asproject/ConsultingTest/_vti_bin/PSI/ProjectServer.svc"behaviorConfiguration="basicHttpBehavior"binding="basicHttpBinding"bindingConfiguration="basicHttpConf"contract="SvcTimeSheet.TimeSheet"name="basicHttp_TimeSheet"/><endpointaddress="http://asproject/ConsultingTest/_vti_bin/PSI/ProjectServer.svc"behaviorConfiguration="basicHttpBehavior"binding="basicHttpBinding"bindingConfiguration="basicHttpConf"contract="SvcQueueSystem.QueueSystem"name="basicHttp_QueueSystem"/><endpointaddress="http://asproject/ConsultingTest/_vti_bin/PSI/ProjectServer.svc"behaviorConfiguration="basicHttpBehavior"binding="basicHttpBinding"bindingConfiguration="basicHttpConf"contract="SvcProject.Project"name="basicHttp_Project"/><endpointaddress="http://asproject/ConsultingTest/_vti_bin/PSI/ProjectServer.svc"behaviorConfiguration="basicHttpBehavior"binding="basicHttpBinding"bindingConfiguration="basicHttpConf"contract="SvcAdmin.Admin"name="basicHttp_Admin"/></client></system.serviceModel><appSettings><addkey="ProjectServer.Integration.LogFileFolder"value="C:\Temp\"/></appSettings></configuration>
Amit Shrivastava