Prerequisites for Reference Code Samples
This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
Most of the code samples included in the Class Library and Web Service Reference conform to a standard format. The samples are designed to be copied into a console application and run as a complete unit. Any exceptions are noted in the sample.
Before running the code samples, you must set up the development environment, configure the application, and change generic constant values to match your environment.
Set Up the Development Environment
Set up a test Project Server system.
Use a test Project Server system whenever you are developing or testing. Even when your code works perfectly, interproject dependencies, reporting, or other environmental factors may cause unintended consequences.
Be sure that you are a valid user on the server, and that you have sufficient permissions.
In some cases you may need to do remote debugging on the server or set up an event handler. For information about remote debugging, see Walkthrough: Creating a Custom Project Server Web Part or How to: Write and Debug a Project Server Event Handler.
Set up a development computer.
You will usually access the Project Server Interface (PSI) through a network. The code samples are designed to be run on a client separate from the server except where noted.
Install Microsoft Visual Studio 2005. Except where noted, the code samples are written in Microsoft Visual C# for use with Microsoft Visual Studio 2005.
Copy Project Server DLLs to the development computer. Copy the following assemblies from [Program Files]\Microsoft Office Servers\12.0\Bin on the Project Server computer to the development computer.
Configure the Application
Create a Windows Console Application.
You will paste the code into this application.
Paste the code.
Copy and paste the complete code sample into the Program.cs file of the application.
Set the namespace.
You can change either the namespace listed at the top of the sample to the application default namespace, or the default application namespace to match the sample. You can find the default application namespace in the application properties.
For example, the code sample for CreateNewAssignment has the namespace Microsoft.SDK.Project.Samples.CreateNewAssignment. Copy the namespace from the Program.cs file and then open the projectproperties pane (on the Project menu, click CreateNewAssignment Properties). Paste the namespace in the Default namespace text box on the Application tab.
Set the Web references.
Many examples require a reference to one or more Web services. These are listed in the sample itself or in the comments that precede the sample. To get the correct namespace of the Web references, be sure to set the default namespace first.
To set a Web reference, do the following:
In Solution Explorer, right-click the References folder, and then clickAdd Web Reference.
In the URL box, type http://ServerName/ProjectServerName/_vti_bin/psi/ServiceName.asmx. If you have Secure Sockets Layer installed, you should use the HTTPS protocol instead of HTTP. Replace ServerName with the name of the server you are using. Replace ProjectServerName with the virtual directory name of your project server site, such as PWA. Replace ServiceName with the name of the service needed, such as Project. Click Go.
Open your Web browser, and navigate to http://ServerName/ProjectServerName/_vti_bin/psi/ServiceName.asmx?WSDL, substituting HTTPS for HTTP if necessary. Save the file to a local directory, such as c:\ServiceName.wsdl. In the Add Web Reference dialog box, for URL, type the file protocol and the path to the file, such as file://c:\ServiceName.wsdl.
The previous URL is the standard URL for Project Server services. If other services are required, they are noted in the example.
After the reference resolves, type the reference name in the Web reference name box. The code samples use a standard of ServiceNameWebSvc. For example, the Project Web service would be named ProjectWebSvc.
For application components that must run on the Project Server computer and have elevated permissions, use the local URL in the Shared Service Provider. For more information about when and how to use the local URL, see Finding the PSI Web Services.
Project Server applications often use other Web services, such as Windows SharePoint Services Web Services. For an example of how to use SharePoint data from the Lists Web service, see Windows SharePoint Services Infrastructure for Project Server.
Set the local DLL references
Any local references for the code sample are listed in the using statements at the top of the sample.
In Solution Explorer, right-click the References folder, and then click Add Reference.
Click Browse, and then browse to the location where you have stored the Project Server DLLs you copied earlier. Choose the DLLs you need.
Ensure that the versions of the assemblies on your development computer match those on the Project Server computer exactly.
Set any other required references.
These references are listed at the top of the sample.
Change Generic Constant Values
Most samples have one or more variables that you must update for the sample to work properly in your environment. In the following example, if you have SSL installed, use the HTTPS protocol instead of HTTP. Replace ServerName with the name of the server you are using. Replace ProjectServerName with the virtual directory name of your project server site, such as PWA.
const string PROJECT_SERVER_URI = "http://ServerName/ProjectServerName/";
Any other variables that must change are noted in the code at the top of the sample.
Any other prerequisites are noted in the sample.
How to view the results from the code sample is not always straightforward. For example, if you create a project, you must publish it before it can appear in the Project Web Access Project Center.
You can verify the code sample results in the following ways:
Use Microsoft Office Project 2007 client to obtain the project from the Project Server computer, and view the items you want.
View the Queue log in Project Web Access My Queued Jobs (http://ServerName/ProjectServerName/MyJobs.aspx).
View published projects in Project Web Access Project Center (http://ServerName/ProjectServerName/projects.aspx).
Use the Project Web Access Server Settings area to view all queues and enterprise objects (http://ServerName/ProjectServerName/admin/admin.aspx). However, you must have administrative permissions before you can access this area.
You can use the Project Web Access Server Settings area to manage enterprise data (http://ServerName/ProjectServerName/admin/admin.aspx). This allows you to delete old items, force check-ins, and manage the job queue for all users, and perform other administrative tasks.