I am using VB.Net. My program is to connect to a remote IPAddress. Once, it
verifies the login information it should display the SessionID and enable
some button . I appreciate your help and thanku in advance
When I run the pgm , I get the error:
Can't parse login information. Object Reference not set to an instance of an
object. I have added the Try-catch in all my functions. In ParseLoginRespo nse
function, it catches the above exception.
I am inclding all the functions I am using below:
Private Function SendXmlRequest( ByRef xml As String)
Try
Dim xmpRequest As HttpWebRequest = WebRequest.Crea te(XmpUrl)
' Instantiate an XmlDocument object to avoid NullReference
exception
Dim xmlDoc As XmlDocument
xmlDoc = New System.Xml.XmlD ocument
'System.Xml.Xml Document(xmldoc = New System.Xml.XmlD ocument)
'Dim xmlDoc As XmlDocument = Nothing
'Dim xmlReader As XmlTextReader
'xmlReader = Nothing
xmpRequest.Meth od = "POST"
xmpRequest.Keep Alive = True
xmpRequest.Cont entType = "text/xml"
Dim writer As StreamWriter
writer = New StreamWriter(xm pRequest.GetReq uestStream())
writer.Write(xm l)
writer.Close()
'Send the request and get the response
Dim HttpWResponse As HttpWebResponse =
CType(xmpReques t.GetResponse() , HttpWebResponse )
'Console.WriteL ine("before sending status")
'Get the status and the headers
Dim iStatCode As Integer = HttpWResponse.S tatusCode
Dim sStatus As String = iStatCode.ToStr ing()
Console.WriteLi ne("Status: {0} {1}", sStatus,
HttpWResponse.S tatusDescriptio n.ToString())
Console.WriteLi ne("Request Headers:")
Console.WriteLi ne(xmpRequest)
Console.WriteLi ne("Response Headers:")
Console.WriteLi ne(HttpWRespons e.Headers.ToStr ing())
'feb15
If Not HttpWResponse Is Nothing Then
Dim XmlRead = New
XmlTextReader(H ttpWResponse.Ge tResponseStream ())
'Dim xmlDoc As XmlDocument
'xmlDoc = New XmlDocument
'Dim xmlDoc = New XmlDocument
xmlDoc.Load(Xml Read)
Return xmlDoc
Else
Console.WriteLi ne("try again")
End If
'Get the response stream
Dim strm As Stream = HttpWResponse.G etResponseStrea m()
'Read the Response stream
Dim encode As Encoding =
System.Text.Enc oding.GetEncodi ng("iso-8859-1")
Dim sr As New StreamReader(st rm, encode)
Console.WriteLi ne("Response: {0}", sr.ReadToEnd())
sr.Close()
'new feb13
'Dim doc As New XmlDocument
'doc.Load(HttpW Response.GetRes ponseStream())
'doc.Save(Conso le.Out)
'end
HttpWResponse.C lose()
'Read the response stream
'Dim sr As StreamReader = New StreamReader(st rm)
'Dim sText As String = sr.ReadToEnd()
'Console.WriteL ine("Response: {0}", sText)
'???Close the stream
'strm.Close()
'Clean up
'xmpRequest = Nothing
'HttpWResponse = Nothing
'MyCredentialCa che = Nothing
'myCred = Nothing
'strm = Nothing
'sr = Nothing
'Feb14
'If sStatus = 200 Then
'The Http Request/Response was successful, now we need to check
the XML that was returned for errors
'If Not RequestHasErrro rs(xmpRequest.r esponseRext) Then
'The overall request was successful so begin to parse the
response XML
'SendXmlRequest = xmpRequest.resp onseXml
'End If
'Else
'End If
'End If
'Else
'Call MsgBox("There was an error. ReadyState = " &
xmpRequest.read yState)
'End If
Catch ex As NullReferenceEx ception
MsgBox("Can't Request page" & vbCrLf & ex.Message)
End Try
End Function
Private Function RequestHasError s(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><Err or>") >= 1 Then
RequestHasError s = True
End If
End Function
Private Function ParseLoginRespo nse(ByRef loginDom As XmlDocument) As
Boolean
' See if the login was successful. If so, get the SessionID.
' Otherwise, log the error.
Try
ParseLoginRespo nse = False
' Setup the Dom to use XPath queries and also setup
' an Xml namespace prefix for use in the XPath queries.
'Call loginDom.setPro perty("Selectio nLanguage", "XPath")
'loginDom.setPr operty("Selecti onNamespaces",
"xmlns:ns='urn: schemas-tms:LoginRespon se'")
Dim filterDoc As New XmlDocument
'Feb14
'Instantiate an XmlNamespaceMan ager object
Dim nsmgr As XmlNamespaceMan ager
nsmgr = New XmlNamespaceMan ager(filterDoc. NameTable)
'Add the namespaces used to the XmlNamespaceMan ager.
nsmgr.AddNamesp ace("ns", "urn:schema s -tms:LoginRespon se")
Dim node As XmlNode
node = loginDom.Select SingleNode("ns: LoginResponse/ns:Status")
'node = New XmlDocument
If node.Value = "Success" Then
' The login was 100% successful so get the SessionID.
'new Feb 14
'If node Is Nothing Then
'for testing
Console.WriteLi ne("Login successful: " & node.Value)
node =
loginDom.Select SingleNode("ns: LoginResponse/ns:SessionID")
'Dim resultImport As XmlNode
'resultImport = filterDoc.Impor tNode(node, True)
'filterDoc.Appe ndChild(resultI mport)
'Return True
'g_SessionID = node.Value
ParseLoginRespo nse = True
'Console.WriteL ine("Login successful: " & node.Value)
'Feb14
Else
'The login was not 100% successful
node =
loginDom.Select SingleNode("ns: LoginResponse/ns:SystemMessag e")
Console.WriteLi ne("Login unsuccessful: " & node.InnerText)
End If
Catch ex As Exception
MsgBox("Can't parse login information" & vbCrLf & ex.Message)
End Try
'Feb13()
'Return True
'Else
' The login was not 100% successful.
'node = loginDom.Select SingleNode("ns: LoginResponse/ns:SystemMessag e")
'Console.WriteL ine("Login unsuccessful: " & node.text)
'End If
'Feb13
'loginDom = Nothing
'node = Nothing
End Function
End Class 0 1604 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Michael Chong |
last post by:
I have an (exe) executable program created in VB.NET 2003 that calls to a
MFC DLL written in VC++.NET 2003. I always get an error msg
"NullReferenceException: Object Reference Not Set to an Instance of an
Object" when my exe calls the following codes:
in VB.NET
Declare Function test Lib "C:\Cyob\IOComm\Debug\IOComm.dll" _
(ByVal a As Long, ByRef b As Integer) As Integer
|
by: Chris Magoun |
last post by:
I suddenly received an unexpected error in my project. I have been working
on this project for some time without this issue. Nothing has changed in the
form that caused the exception. A little experimentation shows that I cannot
run ANY .NET web project without getting this error:
----------------------------------------------------------------------------
----
Object reference not set to an instance of an object.
|
by: blash |
last post by:
Can someone help me? I really don't have a clue.
My company staff told me they often got such error: "Object reference
not set to an instance of an object." when they are in search result
page then tried to access 2nd, or 3rd, etc page. The problem is it
happens sometimes - sometimes when they clicked refresh button, then
everything is ok. Now they told me it happens more frequently. but I
have tried by myself many times and never got...
|
by: Web Team |
last post by:
Server Error in '/netapps' Application.
--------------------------------------------------------------------------------
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference...
|
by: Microsoft |
last post by:
When I try this in my code I alwas get an errormessage: "Object reference
not set to an instance of an object"
Dim g As System.Drawing.Graphics
g.DrawString("Test", New Font("Arial", 12, FontStyle.Bold), Brushes.Black,
0, 0)
Why is this?
Marc
| |
by: Brett |
last post by:
I'm not sure why I keep getting this error, "Object reference not set to an
instance of an object".
Private Function somefunction() as string
Dim MyCurrentClass As New Class1
Try
For i As Integer = 0 To LinkResults.Length - 1
With MyCurrentClass.SqlCmd_Insert_LinkVB
.CommandType = System.Data.CommandType.StoredProcedure
|
by: David Lozzi |
last post by:
Howdy,
I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders!
Now I am making a public function that will take the path of the uploaded image, and resize it with the provided dimensions. My function is below. The current function is returning an error when run from the upload function: A generic error occurred in GDI+. Not sure what exactly that means. From what...
|
by: rushikesh.joshi |
last post by:
Hi All,
I have created my own WebControl and want to add it in my aspx page at
runtime.
it's compiling perfectly, but when i m going to execute, it gives me
error of "Object reference not set to an instance of an object." in my
server control (ascx.cs file)
|
by: Nathan Sokalski |
last post by:
I have a UserControl that I declare programmatically as follows:
Dim userctrl as New rightside_portal()
The codebehind file for this UserControl looks like the following:
Partial Public Class rightside_portal : Inherits System.Web.UI.UserControl
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
|
by: arun1985 |
last post by:
In the project i am using i am having the following code and when i upload it to the server.Its givig me the following error in the global.cs file.
Server Error in '/' Application.
--------------------------------------------------------------------------------
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |