Using the PSI in Visual Studio
Microsoft Office Project Server 2007 is built upon Microsoft .NET Framework 2.0. To realize the full benefit of the version 2.0 datasets, you need to use Microsoft Visual Studio 2005. This article shows how to set a Web reference, set the URL property, and use IntelliSense for the PSI in Visual Studio.
Use the latest released version of Visual Studio 2005, for example, version 8.0.50727 with .NET Framework 2.0.50727. Before installing Visual Studio 2005, you must uninstall any earlier Visual Studio build that uses the .NET Framework 2.0. You can have the .NET Framework versions 1.0 and 1.1 on the same computer along with version 2.0. To see the versions you have installed, look in the following directory:
Using the PSI in Visual Studio involves the following basic actions.
Setting a Web Reference to the PSI
When you set a Web reference to one of the PSI Web services, Visual Studio uses wsdl.exe to generate a proxy class that exposes the methods of that Web service. You can use the automated discovery process to find all of the Web services on a specified server, or type the virtual path of a Web service, as described in Finding the PSI Web Services. For more information about Web services in Visual Studio 2005, see XML Web Services in Managed Code.
To set a Web reference to the PSI in Visual Studio:
On the Project menu, click Add Web Reference.
If Visual Studio is installed on the local test Project Server computer, click Web services on the local computer. Scroll down to see the PSI Web services (Admin, Assignment, …). Click the one you want, and then click Go.
The local URL for the Project Web service, for example, is the following.
You should only use the local URL if you are building an application or component that will run with system-level permissions on the Project Server computer. For example, a timesheet integration component for an external line-of-business (LOB) application must run directly on the Project Server computer and uses the .asmx files in the default Shared Service Provider Web site.
If you are building the application on a remote computer, or if the application should use the user's permissions, type the URL of the Web service you want in the URL text box, and then click Go. For example, type the following.
Type the namespace name you want in the Web reference name text box, and then click Add Reference. You should use a name that is similar to the Web service, to avoid confusion in the code.
For example, if you type WebSvcProject for the Web reference name, and the namespace of your application is LoginDemo, Visual Studio creates the following namespace for the proxy class in the Reference.cs file.
Add a Web reference for each Web service your application will use. Figure 1 shows Web references for the PSI with the arbitrary names WebSvcProjectWeb, and WebSvcQueueSystem, plus the Web references for the Project Web Access LoginForms and LoginWindows Web services.
The PSI Reference uses placeholders for arbitrary names such as WebSvcProject for the PSI Web service namespaces. For more information, see PSI Reference Overview.
You can use the object browser in Visual Studio to see the namespaces and classes in your Web service proxies. For example, double-click WebSvcProject in Solution Explorer to open the object browser and then expand LoginDemo.WebSvcProject on the Object Browser tab. Figure 2 shows that the LoginDemo.WebSvcProject namespace includes a Project class along with the event handlers and datasets that are part of the Project Web service in the PSI.
To access the ReadProjectEntities method, for example, the following Microsoft Visual C# code fragment creates an instance of the Project class, and then calls ReadProjectEntities. To keep the project object in memory for multiple calls, declare it static.
const int ENTITY_PROJECTCUSTOMFIELDS = 32; const int ENTITY_TASKCUSTOMFIELDS = 64; const int ENTITY_RESOURCECUSTOMFIELDS = 128; . . . public static WebSvcProject.Project project = new WebSvcProject.Project(); Guid projectUid = new Guid("b7628f9d-bf4f-427d-8362-e60bebe01c85"); int entities = ENTITY_PROJECTCUSTOMFIELDS | ENTITY_TASKCUSTOMFIELDS | ENTITY_RESOURCECUSTOMFIELDS; WebSvcProject.ProjectDataSet readProjDs = project.ReadProjectEntities(projectUid, entities, WebSvcProject.DataStoreEnum.PublishedStore);
In the previous code, WebSvcProject is the arbitrary namespace of the Project Web service proxy, Project is a class, project is the variable that references the Project instance, and Project() is the class constructor. The projectUid parameter is the GUID of a known published project. The entities parameter is the binary OR of integer values for project, task, and resource custom field entities. The ProjectDataSet returned by the method contains only the requested data.
Setting the URL Property of a Web Reference
To use a Web reference for a PSI Web service in Visual Studio, you must correctly set the URL of the Web service. You can set the URL using either one of the following procedures.
Programmatically set the Url property of the Web class. See Procedure 2 in How to: Log on to Project Server Programmatically.
Or, manually set the URL in the WSDL file, the app.config file, and the Properties page of the application.
Figure 3 shows the incorrect URLs that are set for PSI Web references in the application Properties page.
When you set a Web reference in a Visual Studio project, the WSDL file, app.config file, and application Properties page do not show the correct URL in Visual Studio. The WSDL and DISCO files of Project Server Web services are static because of restrictions for applications that are hosted in Windows SharePoint Services. The Project Server instance name is missing in the URL. For example, a reference in Visual Studio shows the URL of the Project Web service as
To set the URL of a PSI Web reference in Visual Studio:
Add a Web reference to a PSI Web service in Visual Studio, using the procedure in Setting a Web Reference to the PSI. For example, add a reference to
In Solution Explorer, click Show all Files.
Expand the Web reference and open the WSDL file. For example, double-click Project.wsdl in Solution Explorer.
Find the following section. With the Project Web service, for example, change both of the location attributes to
<wsdl:service name="Project"> <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Contains the Project web service for Microsoft Project Server.</wsdl:documentation> <wsdl:port name="ProjectSoap" binding="tns:ProjectSoap"> <soap:address location="http://ServerName/_vti_bin/psi/project.asmx" /> </wsdl:port> <wsdl:port name="ProjectSoap12" binding="tns:ProjectSoap12"> <soap12:address location="http://ServerName/_vti_bin/psi/project.asmx" /> </wsdl:port> </wsdl:service>
Open the application Properties page, and then click the Settings tab. In the LoginDemo application, for example, you can see in Figure 3 the incorrect values of the Web references. Change the URL values to add the Project Server instance name as in Step 4.
Open the app.config file of the Visual Studio project and change the URL to the correct value in the following section (using the same example as in Step 4).
<applicationSettings> <Scrap.Properties.Settings> <setting name="Scrap_ProjectWebSvc_Project" serializeAs="String"> <value>http://ServerName/_vti_bin/psi/project.asmx</value> </setting> </Scrap.Properties.Settings> </applicationSettings>
Using Visual Studio IntelliSense and the PSI Reference
The IntelliSense feature in Visual Studio shows the public members that are available while you are writing code using object variables. For example, Figure 4 shows part of the list of members for the Project object.
The .NET Framework automatically generates a number of methods and events in the Web service proxy that enable clients to use asynchronous calls. These autogenerated proxy class members are public, but some of them are redundant to the existing Web methods in the PSI. Many PSI methods such as QueueCreateProject, QueueCheckInProject, and QueuePublish use the Project Server Queuing service to provide asynchronous calls. If a Web method name begins with Queue, you do not need the corresponding autogenerated Async call for asynchronous programming.
All PSI methods that use the Project Server Queuing service have names that begin with Queue. If the PSI method name does not begin with Queue, then the method is synchronous.
The PSI Reference documents only the Web methods you can see in the browser view of the Web service. For example, in the browser view of project.asmx (see Figure 1 in Introduction to the PSI Web Services), you can see CreateProjectFromTemplate, QueueDeleteFromProject, and ReadProjectEntities. The PSI Reference does not document the additional autogenerated methods that you can see in the Object Browser and the IntelliSense list of methods.