When, I try to run my pgm, I get the message: Object Reference not set to an
instance of object. I get this for line in the ParseLoginResponse function
below:
node = loginDom.selectSingleNode("ns:LoginResponse/ns:Status")
Although, when I try to create instance of XmlNode, it is not allowed. I
appreciate and thankyou in advance
I have included SendXMlRequest, ParseLoginResponse functions below:
Private Function SendXmlRequest(ByRef xml As String)
Dim xmpRequest As HttpWebRequest = WebRequest.Create(XmpUrl)
xmpRequest.Method = "POST"
Dim writer As StreamWriter
writer = New StreamWriter(xmpRequest.GetRequestStream())
writer.Write(xml)
writer.Close()
'Set the necessary HTTP headers
xmpRequest.KeepAlive = True
xmpRequest.ContentType = "text/xml"
'Send the request and get the response
Dim HttpWResponse As HttpWebResponse =
CType(xmpRequest.GetResponse(), HttpWebResponse)
'Get the status and the headers
Dim iStatCode As Integer = HttpWResponse.StatusCode
Dim sStatus As String = iStatCode.ToString()
Console.WriteLine("Status: {0} {1}", sStatus,
HttpWResponse.StatusDescription.ToString())
Console.WriteLine("Request Headers:")
Console.WriteLine(xmpRequest)
Console.WriteLine("Response Headers:")
Console.WriteLine(HttpWResponse.Headers.ToString() )
'Get the response stream
Dim strm As Stream = HttpWResponse.GetResponseStream()
If HttpWResponse Is Nothing Then
xmlReader = New XmlTextReader(HttpWResponse.GetResponseStream())
xmlDoc = New XmlDocument
xmlDoc.Load(xmlReader)
Return xmlDoc
Else
Return xmlDoc
End If
'Read the Response stream
Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")
Dim sr As New StreamReader(strm, encode)
Console.WriteLine("Response: {0}", sr.ReadToEnd())
sr.Close()
HttpWResponse.Close()
‘Close the stream
strm.Close()
'Clean up
xmpRequest = Nothing
HttpWResponse = Nothing
'MyCredentialCache = Nothing
'myCred = Nothing
strm = Nothing
sr = Nothing
End Function
Private Function RequestHasErrors(ByRef xml As String) As Boolean
' Check for the high level error Xml in any response before
' trying to parse the results.
If InStr(xml, "<Response><Error>") >= 1 Then
RequestHasErrors = True
End If
End Function
Private Function ParseLoginResponse(ByRef loginDom As XmlDocument) As
Boolean
' See if the login was successful. If so, get the SessionID.
' Otherwise, log the error.
ParseLoginResponse = False
' Setup the Dom to use XPath queries and also setup
' an Xml namespace prefix for use in the XPath queries.
'Call loginDom.setProperty("SelectionLanguage", "XPath")
'Call loginDom.setProperty("SelectionNamespaces",
"xmlns:ns='urn:schemas-tms:LoginResponse'")
Dim filterDoc As New XmlDocument
'Dim node As MSXML2.IXMLDOMNode
Dim node As XmlNode
node = loginDom.selectSingleNode("ns:LoginResponse/ns:Status")
' The login was 100% successful so get the SessionID.
node = loginDom.SelectSingleNode("ns:LoginResponse/ns:SessionID")
End Function