Subject: post xml using xmlhttp in vb.net
Posted By: datakix Post Date: 10/27/2003 2:23:44 PM
I've run into numerous articles stating that the following code will work in VB.NET. Well it does NOT work for me.

'-- DOES NOT WORK IN VB.NET
Dim xmlDocReq As New MSXML2.DOMDocument40()
xmlDocReq.async = False
xmlDocReq.resolveExternals = False
xmlDocReq.setProperty("ServerHTTPRequest", True)
xmlDocReq.load(Request) **** error: parameter is incorrect *****

The code below is tested and does work in VB.NET. The objective is to load and pass an XML document object from a sending page to a receiving page, and back (basically an echo). Let me know if you have any questions.

--------------------------------------------------
SENDER (Called in Sub Page_Load...)
--------------------------------------------------
        'Set Receiving page
        Dim strURL As String = "http://localhost/DevCitrus/ImportXML/ImportXMLRecieve.aspx"

        'Set path of xml file to pass via HTTP
        Dim xmlPath As String = "C:\TestXML\Manifest.xml"

        'Send XML document to receving page and print result
        Try
            Dim xmlDoc As New MSXML2.DOMDocument40()
            Dim xmlHTTP As New MSXML2.ServerXMLHTTP40()

            'Load xml doc
            If xmlDoc.load(xmlPath) Then
                'Set method, url, async
                xmlHTTP.open("POST", strURL, False)
                'Send XML document
                xmlHTTP.send(xmlDoc.xml)
                'Set content type
                Response.ContentType = "text/xml"
                'Output xml result
                Response.Write(xmlHTTP.responseText)
            Else
                Response.Write(xmlDoc.parseError.reason)
            End If
        Catch ex As Exception
            Response.Write("<MANIFEST><catchError>" + ex.Message + "</catchError></MANIFEST>")
        End Try

--------------------------------------------------
RECEIVER (Called in Sub Page_Load...)
--------------------------------------------------

        'Set Content tpe
        Response.ContentType = "text/xml"

        'Create xmlDoc
        Dim xmlDocReq As New MSXML2.DOMDocument40()

        xmlDocReq.async = False
        xmlDocReq.resolveExternals = False
        xmlDocReq.setProperty("ServerHTTPRequest", True)
        Try
            If xmlDocReq.load(Request.BinaryRead(Request.TotalBytes)) Then
                'Return echo of loaded XML doc
                Response.Write(xmlDocReq.xml)
            Else
                Response.Write("<MANIFEST><parserError>" + xmlDocReq.parseError.reason + "</parserError></MANIFEST>")
            End If
        Catch ex As Exception
            Response.Write("<MANIFEST><catchError>" + ex.Message + "</catchError></MANIFEST>")
        End Try


==================================
Bill Screen
Programmer / Analyst
  
Sun Certified Programmer for the Java 2 Platform
Sun Certified Web Component Developer for J2EE

Sun Certified Enterprise Architect (Part I)

INFINITY SOFTWARE DEVELOPMENT, INC.
3522 Thomasville Rd ~ Suite 200
Tallahassee, FL. 32308-3488
Phone: 850.383.1011
Fax: 850.383.1015
http://www.infinity-software.com
  
==================================


Reply By: gmsetzer Reply Date: 9/24/2004 3:54:12 PM
Hello,

I would like to implement the code you have posted.  How do i reference the MSXML2.DOMDocument40()?

Imports ?

What namespace is MSXML2 under?

Thanks!

Gregg


Go to topic 19737

Return to index page 765
Return to index page 764
Return to index page 763
Return to index page 762
Return to index page 761
Return to index page 760
Return to index page 759
Return to index page 758
Return to index page 757
Return to index page 756