Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将XML从一个ASP.NET页面发送到另一个页面?_Asp.net_Xml_Iis_Msxml6 - Fatal编程技术网

如何将XML从一个ASP.NET页面发送到另一个页面?

如何将XML从一个ASP.NET页面发送到另一个页面?,asp.net,xml,iis,msxml6,Asp.net,Xml,Iis,Msxml6,我花了一整天的时间在ASP.NET上挣扎。我创建了一个.aspx页面,它将XML发送到另一个.aspx页面,该页面读取前面的XML并向第一个页面发送响应 第一页似乎正常,但第二页失败。我怀疑这是环境中的东西,而不是ASP代码,但我无法理解这一点 让我们公开环境: -IIS 6.0 -ASP.NET版本2.0.50727 -Windows Server 2003 R2 SP2标准版 (这已在IIS 7.5、ASP.NET 2和4、Windows Server 2008R2中进行了测试,结果相同)

我花了一整天的时间在ASP.NET上挣扎。我创建了一个.aspx页面,它将XML发送到另一个.aspx页面,该页面读取前面的XML并向第一个页面发送响应

第一页似乎正常,但第二页失败。我怀疑这是环境中的东西,而不是ASP代码,但我无法理解这一点

让我们公开环境: -IIS 6.0 -ASP.NET版本2.0.50727 -Windows Server 2003 R2 SP2标准版

(这已在IIS 7.5、ASP.NET 2和4、Windows Server 2008R2中进行了测试,结果相同)

现在,让我们公开网页代码

SimplePoster.aspx

<%@Page AspCompat=true Language = VB%>
<HTML>
<HEAD>
</HEAD>
<%
'Put together some XML to post off
Dim xmlString = "<?xml version=""1.0""?>" & vbcrlf
xmlString = xmlString & "<Req1>" & vbcrlf
xmlString = xmlString & " <Name>Jenny</Name>" & vbcrlf
xmlString = xmlString & "</Req1>"

'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 ("<b>XML DOC posted off:</b><br>")
response.write (SendDoc.XML & "<br>")
response.write ("<b>Target URL:</b> " & sURL & "<br>")
response.write ("<b>XML DOC Received back: </b><br>")
response.write (NewDoc.Xml)
%>
</HTML>
请注意,响应是空的。。。现在让我们打开
http://localhost/Receiver.aspx

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 
现在,百万美元问题。。。是什么引起了这个问题? *如何在ASP页面中接收XML(或文本)*


我仍在为此挣扎

我尝试了XMLDocument.load/XMLDocument.loadXML(Request/Request.InputStream)的组合。不走运

为了测试这一点,如果我将Receiver.aspx设置为

<%@Page AspCompat=true Language=VB ValidateRequest=false%>
<%
    Dim reqLen As Integer = Request.TotalBytes

'Create a piece of XML to send back

    Dim strResponse As String = "<?xml version=""1.0""?><equis><comment> " & reqLen & " bytes</comment><footer>End of document</footer></equis>"

'Send the response back
response.write(strResponse)
%>

那么,根本就没有输入流?为什么?

我终于成功了。Google和duckduckgoed很多,睡得少。安装Fiddle并使用它使我看到SimplePoster2根本不发送任何内容,并注意到带StreamReader的Receiver2实际上接收并响应由Fiddler直接编写和发送的XML

如此多的时间如雨中的泪水般消磨殆尽。。。
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 
<%@Page AspCompat=true Language=VB ValidateRequest=false%>
<%
    Dim reqLen As Integer = Request.TotalBytes

'Create a piece of XML to send back

    Dim strResponse As String = "<?xml version=""1.0""?><equis><comment> " & reqLen & " bytes</comment><footer>End of document</footer></equis>"

'Send the response back
response.write(strResponse)
%>
XML DOC posted off:
 Jenny  
Target URL: http://localhost:81/Receiver.aspx
XML DOC Received back: 
  0 bytesEnd of document
<%@Page AspCompat=true Language = VB%>

<HTML>
<HEAD>
</HEAD>
<%

    'Put together some XML to post off
    Dim xmlString As String = "<?xml version=""1.0""?>" & vbCrLf
    xmlString = xmlString & "<Req1>" & vbCrLf
    xmlString = xmlString & " <Name>Jenny</Name>" & vbCrLf
    xmlString = xmlString & "</Req1>"    

    'Load the XML into an XMLDOM object
    Dim msXMLDocu As Object = Server.CreateObject("Msxml2.DOMDocument.6.0")
    'msXMLDocu.ValidateOnParse = True
    msXMLDocu.async = False
    msXMLDocu.LoadXML(xmlString)

    'Set the URL of the receiver
    Dim sURL As String = "http://localhost:81/Receiver2.aspx"

    'Call the XML Send function (defined below)
    Dim xmlPoster As Object = Server.CreateObject("MSXML2.ServerXMLHTTP")
    xmlPoster.open("POST", sURL, False)
    xmlPoster.setRequestHeader("Content-Type", "text/xml")
    xmlPoster.send(msXMLDocu.xml)
    Dim NewXmlDoc = Server.CreateObject("Msxml2.DOMDocument.6.0")
    NewXmlDoc.async = False
    'NewXmlDoc.ValidateOnParse = True
    NewXmlDoc.LoadXML(xmlPoster.responseText)

    'We receive back another XML DOM object!

    'Tell the user what happened
    Response.Write("<b>XML DOC posted off:</b><br>")
    Response.Write(msXMLDocu.XML & "<br>")
    Response.Write("<b>Target URL:</b> " & sURL & "<br>")
    Response.Write("<b>XML DOC Received back: </b><br>")
    Response.Write(NewXmlDoc.Xml)

%>
</HTML>
<%@Page AspCompat=true Language=VB ValidateRequest=false%>
<%
    Dim strResponse As String
    Dim reqLen As Integer = Request.TotalBytes

    If (reqLen > 0) Then
        Request.InputStream.Position = 0
        Dim sReader As System.IO.StreamReader = New System.IO.StreamReader(Request.InputStream)
        Dim inputStr As String = sReader.ReadToEnd()

        Dim msXmlDocu As Object = CreateObject("Msxml2.DOMDocument.6.0")
        msXmlDocu.async = False
        Dim xmlLoaded As Boolean = msXmlDocu.loadXML(inputStr)
        If (xmlLoaded) Then
            Dim listItem As Object = msXmlDocu.selectnodes("Req1")

            strResponse = "<?xml version=""1.0""?>" & vbCrLf & "<doc><status>OK</status><length>" & reqLen & " bytes</length>"
            strResponse = strResponse & "<Person>" & 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 & " <Name>Thanks " & name & "</Name>" & vbCrLf
            Next

            strResponse = strResponse & "</Person></doc>"

            'strResponse = "<?xml version=""1.0""?><doc><status>OK</status><length>" & reqLen & " bytes</length><content>" & stri & " </content></doc>"
        Else
            'Create a piece of XML to send back
            strResponse = "<?xml version=""1.0""?><doc><status>Error</status><reason>Data posted, but could not load XML Document</reason></doc>"
        End If
    Else
        'Create a piece of XML to send back
        strResponse = "<?xml version=""1.0""?><doc><status>Error</status><reason>No data posted available</reason></doc>"
    End If


        'Send the response back
        Response.Write(strResponse)
%>
Request.InputStream.Position = 0
Dim sReader As System.IO.StreamReader = New System.IO.StreamReader(Request.InputStream)
Dim inputStr As String = sReader.ReadToEnd()
[Msxml2.DOMDocument.6.0].loadXML(inputStr)