Programmatic Logon to Microsoft Project Server
This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
Before a client application can make method calls to the PDS, it must first log in to the Microsoft Project Server. Microsoft Project Server supports two methods of programmatic logon: Microsoft Windows® Integrated authentication, and Microsoft Project authentication.
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 in using Windows integrated authentication, as shown in the following Visual Basic 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
This code waits for the Microsoft 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").