title: How do I send XML from one ASP.NET page to another?
body: <p>I've spent all day struggling with ASP.NET. I've made an .aspx page that sends XML to other .aspx page that reads the previous XML and sends a response to the first page.</p>
  
  <p>The first page appears to work, but the second fails. I suspect it's something in environment, rather than ASP code, but I can't figure the point.</p>
  
  <p>Let's expose the environments:
  - IIS 6.0
  - ASP.NET version 2.0.50727
  - Windows Server 2003 R2 SP2 Std. edition</p>
  
  <p>(This has been tested in IIS 7.5, ASP.NET 2 and 4, Windows Server 2008R2, with same results)</p>
  
  <p>Now, let's expose the webpages codes.</p>
  
  <p>SimplePoster.aspx</p>
  
  <pre><code>&lt;%@Page AspCompat=true Language = VB%&gt;
  &lt;HTML&gt;
  &lt;HEAD&gt;
  &lt;/HEAD&gt;
  &lt;%
  'Put together some XML to post off
  Dim xmlString = "&lt;?xml version=""1.0""?&gt;" &amp; vbcrlf
  xmlString = xmlString &amp; "&lt;Req1&gt;" &amp; vbcrlf
  xmlString = xmlString &amp; " &lt;Name&gt;Jenny&lt;/Name&gt;" &amp; vbcrlf
  xmlString = xmlString &amp; "&lt;/Req1&gt;"
  
  'Load the XML into an XMLDOM object
  Dim SendDoc = server.createobject("Microsoft.XMLDOM")
  SendDoc.ValidateOnParse= True
  SendDoc.LoadXML(xmlString)
  
  'Set the URL of the receiver
  Dim sURL = "http://myserver/Receiver.aspx"
  
  'Call the XML Send function (defined below)
  Dim poster = Server.CreateObject("MSXML2.ServerXMLHTTP")
  poster.open("POST", sURL, false)
  poster.setRequestHeader("CONTENT_TYPE", "text/xml")
  poster.send(SendDoc)
  Dim NewDoc = server.createobject("Microsoft.XMLDOM")
  newDoc.ValidateOnParse= True
  newDoc.LoadXML(poster.responseTEXT)
  
  'We receive back another XML DOM object!
  
  'Tell the user what happened
  response.Write ("&lt;b&gt;XML DOC posted off:&lt;/b&gt;&lt;br&gt;")
  response.write (SendDoc.XML &amp; "&lt;br&gt;")
  response.write ("&lt;b&gt;Target URL:&lt;/b&gt; " &amp; sURL &amp; "&lt;br&gt;")
  response.write ("&lt;b&gt;XML DOC Received back: &lt;/b&gt;&lt;br&gt;")
  response.write (NewDoc.Xml)
  %&gt;
  &lt;/HTML&gt;
  </code></pre>
  
  <p>Receiver.aspx</p>
  
  <pre><code>&lt;%@Page AspCompat=true Language = VB%&gt;
  &lt;%
  'Create an XML DOM Object to receive the request
  'dim docReceived = CreateObject("Microsoft.XMLDOM") 'docReceived.load(request) Valid only in IIS 5.0?
  dim docReceived = CreateObject("Msxml2.DOMDocument.6.0")
  docReceived.async = False
  docReceived.load(Request)
  
  'Create a piece of XML to send back
  Dim listItem = docReceived.selectnodes("Req1")
  
  Dim strResponse = "&lt;?xml version=""1.0""?&gt;" &amp; vbcrlf
  strResponse = strResponse &amp; "&lt;Person&gt;" &amp; vbcrlf
  
  'For the purposes of this example we modify
  'the response based on the request
  Dim node
  Dim name
  for each node in listItem
  name = node.selectsinglenode("Name").firstchild.nodevalue
  strResponse = strResponse &amp; " &lt;Name&gt;Thanks " &amp; name &amp; "&lt;/Name&gt;" &amp; vbcrlf
  next
  
  strResponse = strResponse &amp; "&lt;/Person&gt;"
  
  'Send the response back
  response.write(strResponse)
  %&gt;
  </code></pre>
  
  <p>Now, let's open <code>http://myserver/SimplePoster.aspx</code> with IE. The output is:</p>
  
  <pre><code>XML DOC posted off:
  Jenny 
  Target URL: http://localhost/Test1/Receiver.aspx
  XML DOC Received back:
  </code></pre>
  
  <p>Note that response is empty... now let's open <code>http://localhost/Receiver.aspx</code>:</p>
  
  <pre><code>Server Error in '/' Application.
  --------------------------------------------------------------------------------
  
  Value does not fall within the expected range. 
  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.ArgumentException: Value does not fall within the expected range.
  
  Source Error: 
  
  
  Line 5:  dim docReceived = CreateObject("Msxml2.DOMDocument.6.0")
  Line 6:  docReceived.async = False
  Line 7:  docReceived.load(Request)
  Line 8:  
  Line 9:  'Create a piece of XML to send back
  
  
  Source File: C:\Inetpub\TestAxXMLInbox\Receiver.aspx    Line: 7 
  
  Stack Trace: 
  
  
  [ArgumentException: Value does not fall within the expected range.]
     Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack, Boolean IgnoreReturn) +776
     Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, Boolean IgnoreReturn) +367336
     ASP.test1_receiver_aspx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in C:\Inetpub\TestAxXMLInbox\Test1\Receiver.aspx:7
     System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +98
     System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +20
     System.Web.UI.Page.Render(HtmlTextWriter writer) +26
     System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25
     System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
     System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
     System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2558
  
  
  
  
  --------------------------------------------------------------------------------
  Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433 
  </code></pre>
  
  <p><strong>Now, the million dollars question... what is raising this issue?</strong>
  *<em>How can I receive XML (or text) in an ASP page? *</em></p>
  
  <hr>
  
  <p>I'm still struggling with this.</p>
  
  <p>I've tried combinations of XMLDocument.load/XMLDocument.loadXML (Request/Request.InputStream). No luck.</p>
  
  <p>In order to test this, if I set Receiver.aspx to</p>
  
  <pre><code>&lt;%@Page AspCompat=true Language=VB ValidateRequest=false%&gt;
  &lt;%
      Dim reqLen As Integer = Request.TotalBytes
  
  'Create a piece of XML to send back
  
      Dim strResponse As String = "&lt;?xml version=""1.0""?&gt;&lt;equis&gt;&lt;comment&gt; " &amp; reqLen &amp; " bytes&lt;/comment&gt;&lt;footer&gt;End of document&lt;/footer&gt;&lt;/equis&gt;"
  
  'Send the response back
  response.write(strResponse)
  %&gt;
  </code></pre>
  
  <p>The result is always:</p>
  
  <pre><code>XML DOC posted off:
   Jenny  
  Target URL: http://localhost:81/Receiver.aspx
  XML DOC Received back: 
    0 bytesEnd of document
  </code></pre>
  
  <p>So, no input stream at all? Why?</p>