Calling PDS via XMLHTTP object instead of SOAP toolkit

M

Mark Worl

Just posting this for others to reference since I never found an
answer in the news group on how to call the PDS service using XMLHTTP
object instead of the Soap Client from the Soap Toolkit.

The tricky part was getting the Soap envelope correct.
Here is an example of the SOAP sent to the PDS for the PDSInfo
function.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema"
xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAPSDK4:SoapXMLRequest
xmlns:SOAPSDK4="http://tempuri.org/message/">
<sCookie type="xsd:string">svc={D8D06337-9C12-466D-84BF-57767FEDF8AD}&amp;session={AA6D9465-8E75-4965-9BB4-25B08D076F7F}&amp;prxy={EFBA0018-337F-4A35-9454-E7E1155F92A4}&amp;org=projectserver</sCookie>
<sXML type="xsd:string">&lt;Request&gt;&lt;PDSInfo/&gt;&lt;/Request&gt;</sXML>
</SOAPSDK4:SoapXMLRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Here is the VBA call from MS Access 97.
Private Sub btnPDSInfo_Click()
Dim sURL As String, sXML As String, sEnv As String, sSecCookie As
String
Dim xmlhtp As New MSXML2.XMLHTTP, xmlDoc As New DOMDocument, oNode
As IXMLDOMNode

On Error GoTo btnPDSInfo_Click_Error:

' sCookie was obtained in another procedure per instructions in the
SDK.
' Ampout just replaces & with &amp; which are found in the cookie.
sSecCookie = AmpOut(sCookie)

sURL = "http://yourserver/projectserver/PDS.wsdl"

' Turn stuff like < into &gt;
sXML = EscapeRequest("<Request><PDSInfo/></Request>")

sEnv = "<?xml version=""1.0"" encoding=""UTF-8""
standalone=""no""?>" & Chr(13) & _
"<SOAP-ENV:Envelope
xmlns:SOAPSDK1=""http://www.w3.org/2001/XMLSchema""
xmlns:SOAPSDK2=""http://www.w3.org/2001/XMLSchema-instance""
xmlns:SOAPSDK3=""http://schemas.xmlsoap.org/soap/encoding/""
xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"">" &
Chr(13) & _
" <SOAP-ENV:Body
SOAP-ENV:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/"">"
& Chr(13) & _
" <SOAPSDK4:SoapXMLRequest
xmlns:SOAPSDK4=""http://tempuri.org/message/"">" & Chr(13) & _
" <sCookie type=""xsd:string"">" & sSecCookie &
"</sCookie>" & Chr(13) & _
" <sXML type=""xsd:string"">" & sXML & "</sXML>" &
Chr(13) & _
" </SOAPSDK4:SoapXMLRequest>" & Chr(13) & _
"</SOAP-ENV:Body>" & Chr(13) & _
"</SOAP-ENV:Envelope>"

txtSOAPSent = sEnv

xmlhtp.Open "post", sURL, False
xmlhtp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
xmlhtp.setRequestHeader "soapAction",
"http://tempuri.org/action/CMain.SoapXMLRequest"
xmlhtp.send sEnv

' Next statement strips off the soap envelope and creates an XML
document with just the results.
xmlDoc.loadXML "<?xml version=""1.0"" encoding=""UTF-8""?>" &
xmlhtp.responseXML.lastChild.Text

' Just getting the HRESULTS node. You can query for elements as you
need.
Set oNode = xmlDoc.selectSingleNode("//HRESULT")

'txtXML is a textbox on my form.
txtXML = xmlDoc.xml

Exit Sub

btnPDSInfo_Click_Error:
MsgBox Err.Description & vbCrLf & Str(Err.Number)
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top