Programmatic Logon to Project Server
Before a client application can make method calls to the PDS, it must first log on to Microsoft Office Project Server 2003. Project Server supports two methods of programmatic logon: Microsoft Windows integrated authentication, and Microsoft Project authentication.
Note You should not use the same logon name with Microsoft Office Project Professional 2003 and another PDS application at the same time, to check out and modify the same project on Project Server. If you do, the most recent changes made with one application will overwrite previous changes made in the other application.
Windows integrated authentication does not require explicit logon information to be sent with the logon request. A client calls the LgnIntAu.asp page to log on using Windows authentication, as shown in the following Visual Basic 6 example:
Dim sURL As String
sURL = "http://myserver/projectserver/LgnIntAu.asp"
Dim oXMLDocument As DOMDocument30
Set oXMLDocument = New DOMDocument30
oXMLDocument.Load sURL
In this example, the Microsoft XML Parser (MSXML) is used to make the logon request. Although not required, the parser makes it easier to retrieve the security cookie needed to make PDS method calls.
To use Microsoft Project authentication, the previous code would be modified to use the following URL:
sURL = "http://myserver/projectserver/LgnPSAu.asp"
sURL = sURL & "?un=Administrator&pwd="
Notice that the Microsoft Project logon information is passed in the query string.
The key information needed from a successful logon is in the PDS security cookie. The following code shows how to use the MSXML parser to extract this cookie:
'Wait for the XML Document to load from Microsoft Project Server
Const cTimeout As Long = 45
Dim startTime As Long, elapsed As Long
startTime = Timer
Do While oXMLDocument.readyState < 4
DoEvents
elapsed = Timer - startTime
'cTime is a constant set to number of seconds to wait for timeout
If elapsed > cTimeout Then GoTo errTimeout
Loop
Dim sCookie As String
Dim oNode As IXMLDOMNode
If oXMLDocument.parseError.errorCode = 0 Then
If Not oXMLDocument Is Nothing Then
Set oNode = oXMLDocument.selectSingleNode("Reply/Cookie")
If Not oNode Is Nothing Then
sCookie = oNode.Text
End If
End If
Else
sCookie = ""
End If
errTimeout:
MsgBox prompt:="Login Timeout Occurred." & vbCrLf & "Elapsed time = " _
& elapsed & " seconds" & vbCrLf & "xmlDocument.ReadyState = " & _
oXMLDocument.readyState, Title:="Login Timeout"
MsgBox prompt:=oXMLDocument.xml
The code waits for the Project Server response (in this example, the application will time out after 45 seconds). If logon is successful, an XML response is returned, similar to the following example:
<?xml version="1.0"?>
<Reply>
<HRESULT>0</HRESULT>
<Cookie>
<![CDATA[svc={D8D06337-9C12-466D-84BF-57767FEDF8AD}
&session={CCB39B94-A3D8-4C0B-AFA1-49604AF6C3D9}
&prxy={EFBA0018-337F-4A35-9454-E7E1155F92A4}
&org=projectserver]]>
</Cookie>
</Reply>
The parser’s selectSingleNode method allows you to easily extract the security cookie into a string. This cookie string is then passed into subsequent calls to the SoapXMLRequest method (see Using SOAP to call PDS Methods).