Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB.NET
|
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 27th, 2003, 03:27 PM
Registered User
 
Join Date: Oct 2003
Posts: 3
Thanks: 0
Thanked 1 Time in 1 Post
Default post xml using xmlhttp in vb.net

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.TotalByt es)) 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

==================================


 
Old November 14th, 2003, 02:41 PM
Registered User
 
Join Date: Nov 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This one should work. If the status code is 500 just report the error as plain text else if 200 load the xml doc or whatever you plan on doing with it.

---------------------------
Imports System.Xml

Public Class WebForm1
    Inherits System.Web.UI.Page

... Web Form Designer Generated Code ...

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim sProcess As String
        Dim objXML As XmlDocument = New XmlDocument()

        Try
            sProcess = "Load XML"
            objXML.Load(Request.InputStream)

            Response.StatusCode = 200
            Response.StatusDescription = "OK"
            Response.ContentType = "text/xml"
            Response.Write(objXML.InnerXml())

        Catch ex As System.Xml.XmlException
            Response.StatusCode = 500
            Response.StatusDescription = "Process: " & sProcess & " - " & ex.Message
            Response.ContentType = "text/plain"
            Response.Write("HTTP Error " & CStr(Response.StatusCode) & ": Process: " & sProcess & " - " & ex.Message)

        Finally
            objXML = Nothing
        End Try
    End Sub

-------------------------
Warren
 
Old December 21st, 2004, 11:12 AM
Registered User
 
Join Date: Dec 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to kboek
Default

Have been wrestling with this code almost all day. When implementing it into my aspx page of my VB.NET I receive the following error:

Code:
Cannot have a DOCTYPE declaration outside of a prolog. 
Error processing resource 'http://www.mysite.com/...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
----------^
When posting the XML (using an ASP:Button_OnClick), I'm indeed redirected to a new page (indicated as "RECEIVER" in former posts) but not only my XML response is written by using "Response.Write(xmlHTTP.responseText)" but the system is trying to display the complete page that I posted from, including it's ViewState! Maybe that's why the error message appears: it tries to parse XML, and then all of the sudden finds HTML metadata...

Anybody got an idea to help me?
 
Old December 21st, 2004, 01:31 PM
Registered User
 
Join Date: Dec 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to kboek
Default

::UPDATE::

Installed MSXML 4.0 SP2 on my webserver (Win2003 Standard) and now the problems got even more frustrating; when running the code - posting the document - it asks me for a Windows username and password (as if Windows authentication was enabled)

First of all, of course, it shouldn't ask for a password. But the administrator name and password aren't accepted. After a few tries or pressing Cancel this message shows up:

Access is denied;
System.UnauthorizedAccessException: Access is denied;
MSXML2.ServerXMLHTTP40Class.send(Object varBody) +0

Please let somebody tell me how to go from here...






Similar Threads
Thread Thread Starter Forum Replies Last Post
post xml using xmlhttp in vb.net datakix Classic ASP XML 4 August 7th, 2009 05:31 AM
How do I post a XML file to an URL using VB? chengjianjin Visual Basic 2005 Basics 3 April 28th, 2008 05:24 AM
Request Post XMLHttp : Need Help Kyum BOOK: Professional Ajax 2nd Edition ISBN: 978-0-470-10949-6 5 July 5th, 2007 09:51 PM
XML Post From VB to asp page LanceAtCti VB How-To 2 July 13th, 2006 08:58 AM
XML Post using microsoft.XMLHTTP csmajor231 XML 0 April 5th, 2004 03:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.