Accessing webservice, rendering XML --> HTML results in InvalidActiveXStateException

matthew.s.chin

New member
Joined
Jan 10, 2005
Messages
1
Programming Experience
Beginner
Accessing webservice, rendering XML --> HTML results in InvalidActiveXStateException

First, let me say: I am a VB.NET beginner. I have been to one class, and I am currently going through O'Reilly's ONDOTNET.COM.

I am having trouble rendering XML from a local webservice into HTML, and displaying it successfully in a Microsoft Web Browser toolbar component.

The application is straight foward. It is a simple form, with two buttons (POST/GET). Depending on your "on click", it will access a local web service, grab the xml, and render it into an HTML page, displayed in the Microsoft Web Browser box. The basis for the application is O'Reilly's book, and the URL in question is http://www.ondotnet.com/lpt/a/1562.

Under Visual Studio 2003, with option strict and explicit "on", O'Reilly's code will not compile. I am required to cast the variables explicitly. Below you will find my code, based off of O'Reilly's book. However, every time I run it, I get the following error message on line 106 (click on GET button) or line 133 (click on POST button)--e.g., doc = DirectCast(myWebBrowser.Document, mshtml.HTMLDocument

ERROR MESSAGE

---

An unhandled exception of type 'InvalidActiveXStateException' occurred in axinterop.shdocvw.dll

---

I have extentively checked google and multiple forums. I have set FORM1 property "TopMost" to FALSE. Assuming the error could result in an attempt to render the data to a "non-maximized" window, I also set:

Me.WindowState = FormWindowState.Maximized

in the Windows Form Designer generated code area. I also attempted a boolean variable with If statements, checking whether the form had successfully loaded. No such luck.

I can successfully execute the web services via a browser, calling the various methods, passing variables in the browser for the GET, and via form variables in the POST. I have also successfully written thick clients that return and display the web service data perfectly--the web service performs simple SQL queries against a MSSQL Pubs database.

Hopefully one of you can identify the problem. Gut tells me, something is not intializing, or the data is not being returned and redenered fast enough before another event is executing.

--Matthew

PublicClass Form1

Inherits System.Windows.Forms.Form

#
Region " Windows Form Designer generated code "

PublicSubNew()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

EndSub

'Form overrides dispose to clean up the component list.

ProtectedOverloadsOverridesSub Dispose(ByVal disposing AsBoolean)

If disposing Then

If
Not (components IsNothing) Then

components.Dispose()

EndIf

End
If

MyBase
.Dispose(disposing)

EndSub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

FriendWithEvents cmdGet As System.Windows.Forms.Button

FriendWithEvents cmdPOST As System.Windows.Forms.Button

FriendWithEvents myWebBrowser As AxSHDocVw.AxWebBrowser

<System.Diagnostics.DebuggerStepThrough()>
PrivateSub InitializeComponent()

Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))

Me.cmdGet = New System.Windows.Forms.Button

Me.cmdPOST = New System.Windows.Forms.Button

Me.myWebBrowser = New AxSHDocVw.AxWebBrowser

CType(Me.myWebBrowser, System.ComponentModel.ISupportInitialize).BeginInit()

Me.SuspendLayout()

'

'cmdGet

'

Me.cmdGet.Location = New System.Drawing.Point(80, 24)

Me.cmdGet.Name = "cmdGet"

Me.cmdGet.TabIndex = 0

Me.cmdGet.Text = "GET"

'

'cmdPOST

'

Me.cmdPOST.Location = New System.Drawing.Point(232, 24)

Me.cmdPOST.Name = "cmdPOST"

Me.cmdPOST.TabIndex = 1

Me.cmdPOST.Text = "POST"

'

'myWebBrowser

'

Me.myWebBrowser.ContainingControl = Me

Me
.myWebBrowser.Enabled = True

Me
.myWebBrowser.Location = New System.Drawing.Point(32, 72)

Me.myWebBrowser.OcxState = CType(resources.GetObject("myWebBrowser.OcxState"), System.Windows.Forms.AxHost.State)

Me.myWebBrowser.Size = New System.Drawing.Size(300, 150)

Me.myWebBrowser.TabIndex = 2

'Me.WindowState = FormWindowState.Maximized

Me.myWebBrowser.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _

Or System.Windows.Forms.AnchorStyles.Left) _

Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(392, 302)

Me.Controls.Add(Me.myWebBrowser)

Me.Controls.Add(Me.cmdPOST)

Me.Controls.Add(Me.cmdGet)

Me.Name = "Form1"

Me.Text = "Form1"

CType(Me.myWebBrowser, System.ComponentModel.ISupportInitialize).EndInit()

Me.ResumeLayout(False)

EndSub

#EndRegion

Private
Sub cmdGet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGet.Click

Dim oXMLHTTP As MSXML2.XMLHTTP

Dim oDOM As MSXML2.DOMDocument

Dim oXSL As MSXML2.DOMDocument

Dim myWebBrowser As AxSHDocVw.AxWebBrowser

Dim doc As mshtml.HTMLDocument

oXMLHTTP =
New MSXML2.XMLHTTP

oXMLHTTP.open("Get", "http://localhost/PubsWS/PubsWS.asmx/GetBooks",
False)

oXMLHTTP.send()

oDOM =
CType(oXMLHTTP.responseXML, MSXML2.DOMDocument)

oXSL =
New MSXML2.DOMDocument

oXSL.load(App_Path() & "templateTitle.xsl")

myWebBrowser =
New AxSHDocVw.AxWebBrowser

doc =
DirectCast(myWebBrowser.Document, mshtml.HTMLDocument)

doc.write(
CStr(oDOM.transformNode(oXSL)))

doc.close()

oXSL =
Nothing

oDOM = Nothing

oXMLHTTP = Nothing

End
Sub

Private
Sub cmdPOST_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPOST.Click

Dim oXMLHTTP As MSXML2.XMLHTTP

Dim oDOM As MSXML2.DOMDocument

Dim oXSL As MSXML2.DOMDocument

Dim doc As mshtml.HTMLDocument

oXMLHTTP =
New MSXML2.XMLHTTP

oXMLHTTP.open("POST", "http://localhost/PubsWS/PubsWS.asmx/GetAuthor",
False)

oXMLHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")

oXMLHTTP.send("sSSN=172-32-1176")

oDOM =
CType(oXMLHTTP.responseXML, MSXML2.DOMDocument)

oXSL =
New MSXML2.DOMDocument

oXSL.load(App_Path() & "templateAuthor.xsl")

myWebBrowser =
New AxSHDocVw.AxWebBrowser

doc =
DirectCast(myWebBrowser.Document, mshtml.HTMLDocument)

doc.write(
CStr(oDOM.transformNode(oXSL)))

doc.close()

oXSL =
Nothing

oDOM = Nothing

oXMLHTTP = Nothing

End
Sub

Public
Function App_Path() AsString

Return
System.AppDomain.CurrentDomain.BaseDirectory()

EndFunction

End
Class

 
Back
Top