473,324 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Xml in Vb.net: Null reference exception

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


Feb 14 '06 #1
0 1178

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: Eric | last post by:
There is a VB.NET critique on the following page: http://www.vb7-critique.741.com/ for those who are interested. Feel free to take a look and share your thoughts. Cheers, Eric. Ps: for those...
2
by: Softer | last post by:
Hi I have been installed Longhorn, alfa version from PDC 2003. I tryed to install Visual Studio 8.0 "Whidbey", version Beta March 2004, under Longhorn and doesen't work. : I instaled Whidbey under...
5
by: Boniek | last post by:
Hi I define a public property in a new form and I can see this property in table of Properties in Visual. How I can hide this property to see only in code ? Thank's Boniek
15
by: Sharon | last post by:
I’m trying to build a generic Publisher-Subscriber that will work over the net, so I’m using the Remoting. I wish that the subscriber user will be notify about the messages sent by the...
33
by: Ken | last post by:
I have a C# Program where multiple threads will operate on a same Hashtable. This Hashtable is synchronized by using Hashtable.Synchronized(myHashtable) method, so no further Lock statements are...
18
by: amdishigh | last post by:
We are experiencing the following problems concerning ASP.NET: our ASP.NET application, written in .NET 1.1 platform, and hosted in IIS 5.0 environment, experience frequent session timeout problem....
7
by: Chuck Hartman | last post by:
I have a Windows service that requests web pages from a site using an HttpWebRequest object. When I try to request a page from an ASP.NET 2 site, I get a WebException with message "The remote...
5
by: Peter Proost | last post by:
Hi I got this piece of c# code which runs ok but now I translated it to vb.net (see bottom of post for both pieces) and it keeps erroring out at pi.SetValue(testForm, newValue, x) with this error:...
6
by: ransoma22 | last post by:
I developing an application that receive SMS from a connected GSM handphone, e.g Siemens M55, Nokia 6230,etc through the data cable. The application(VB.NET) will receive the SMS automatically,...
0
by: shamirza | last post by:
· When was .NET announced? Bill Gates delivered a keynote at Forum 2000, held June 22, 2000, outlining the .NET 'vision'. The July 2000 PDC had a number of sessions on .NET technology, and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.