"Request" is the asp request object. I've found the XmlDocument object, but the XML is coming to the page via the HTTP POST, and I can't figure out how to load it into the XML object.
Ok, then it's only "slightly" harder to load the XmlDocument.
First, the "body" of the request will be available via the Request.InputStream property. This will not include any headers, so I'm assuming that it will only include the contents of your XML. You can verify by using the following code to capture the contents
of the stream into a string (execute in the Page_Load):
System.IO.StreamReader sr = new System.IO.StreamReader(Request.InputStream);
string requestContents = sr.ReadToEnd();
sr.Close();
If it is only XML that is coming in (i.e., it won't look like a bunch of URL parameters separated by &'s), then you should be able to load the entire Request stream into the XmlDocument via the following:
System.Xml.XmlDocument objXMLDoc = new System.Xml.XmlDocument();
objXMLDoc.Load(Request.InputStream);
Running the code objXMLDoc.Load(Request.InputStream) returns the error: convert from 'System.IO.Stream' to 'string'. I've added '.ToString()', but that results in just the text string
'System.Web.HttpInputStream'.
Odd. At first, I thought I messed up since I used "air coding" instead of something that was compiled and tested. But, I then made a simple project doing the same thing, and it works as I expected. .NET Framework 1.1 (VS.NET
2003)
Here's the Page_Load side on the ASPX (this is a VB.NET webform named webform1.aspx):
Private
Sub Page_Load(ByVal sender
As System.Object, ByVal e
As System.EventArgs) Handles
MyBase.Load
Dim x
As New System.Xml.XmlDocument
Try
x.Load(Request.InputStream)
Response.Write(x.OuterXml)
Response.Write(Request.InputStream.ToString())
Catch
Response.Write("Error during XML read")
End
Try
End
Sub
And here's a sample client (this is a C# console app) that opens the webform1.aspx page and submits XML as a string to the Request stream:
System.Xml.XmlDocument xml =
new System.Xml.XmlDocument();
System.Net.HttpWebRequest req = System.Net.HttpWebRequest.Create
("http://localhost/webscratch/webform1.aspx") as System.Net.HttpWebRequest;
req.Method = "POST";
System.IO.StreamWriter sw = new System.IO.StreamWriter(req.GetRequestStream());
sw.Write(xml.OuterXml);
sw.Close();
System.Net.HttpWebResponse resp = req.GetResponse()
as System.Net.HttpWebResponse;
Console.WriteLine (new System.IO.StreamReader(resp.GetResponseStream()).ReadToEnd());
The result was what I expected, with the beginning of the Console output being:
<CustomerInfo><Name>mdoctor</Name><Age>21</Age></CustomerInfo>System.Web.HttpInputStream
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
...
With objWinHTTP
.Open "POST", strURL, False
.SetRequestHeader "Content-type", "text/xml"
.Send strXML
.WaitForResponse
getserverINIKeys = objWinHTTP.ResponseText
End With
Set objWinHTTP = Nothing
End Sub
my aspx file :
Private Sub Page_Load(ByVal sender
As System.Object,
ByVal e As System.EventArgs)
Handles MyBase.Load
Dim strResponseXML
As String
Dim obj As
New WinHttp.WinHttpRequest
Dim objXMLDOM
As New MSXML2.DOMDocument
Dim strRequestXML
objXMLDOM.load(Request)
strRequestXML = objXMLDOM.xml
If strRequestXML <> ""
Then
obj_RespFill =
New Resp_fill
strResponseXML = "XML Has Values and the values are " & vbCrLf & strRequestXML
RHPT
Member
255 Points
51 Posts
Converting MSXML Code to C#/.NET
Aug 11, 2005 02:55 PM|LINK
Set objXMLDoc = Server.CreateObject("Msxml2.DOMDocument.3.0")
objXMLDoc.load Request
Thank you
JasonFollas
Participant
860 Points
170 Posts
Re: Converting MSXML Code to C#/.NET
Aug 13, 2005 02:22 AM|LINK
Assuming that it's just a string (because that's the easiest):
You'll find that System.Xml.XmlDocument is the closest to the DOMDocument object, and that your code is nearly identical.
System.Xml.XmlDocument objXMLDoc = new System.Xml.XmlDocument();
objXMLDoc.Load(Request);
A View Inside My Head
RHPT
Member
255 Points
51 Posts
Re: Converting MSXML Code to C#/.NET
Aug 13, 2005 03:35 AM|LINK
JasonFollas
Participant
860 Points
170 Posts
Re: Converting MSXML Code to C#/.NET
Aug 15, 2005 01:48 PM|LINK
First, the "body" of the request will be available via the Request.InputStream property. This will not include any headers, so I'm assuming that it will only include the contents of your XML. You can verify by using the following code to capture the contents of the stream into a string (execute in the Page_Load):
System.IO.StreamReader sr = new System.IO.StreamReader(Request.InputStream);
string requestContents = sr.ReadToEnd();
sr.Close();
If it is only XML that is coming in (i.e., it won't look like a bunch of URL parameters separated by &'s), then you should be able to load the entire Request stream into the XmlDocument via the following:
System.Xml.XmlDocument objXMLDoc = new System.Xml.XmlDocument();
objXMLDoc.Load(Request.InputStream);
A View Inside My Head
RHPT
Member
255 Points
51 Posts
Re: Converting MSXML Code to C#/.NET
Aug 15, 2005 04:29 PM|LINK
Running the code objXMLDoc.Load(Request.InputStream) returns the error: convert from 'System.IO.Stream' to 'string'. I've added '.ToString()', but that results in just the text string 'System.Web.HttpInputStream'.
JasonFollas
Participant
860 Points
170 Posts
Re: Converting MSXML Code to C#/.NET
Aug 15, 2005 10:57 PM|LINK
Here's the Page_Load side on the ASPX (this is a VB.NET webform named webform1.aspx):
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim x As New System.Xml.XmlDocument
Try
x.Load(Request.InputStream)
Response.Write(x.OuterXml)
Response.Write(Request.InputStream.ToString())
Catch
Response.Write("Error during XML read")
End Try
End Sub
And here's a sample client (this is a C# console app) that opens the webform1.aspx page and submits XML as a string to the Request stream:
System.Xml.XmlDocument xml = new System.Xml.XmlDocument();
xml.LoadXml("<CustomerInfo><Name>mdoctor</Name><Age>21</Age></CustomerInfo>");
System.Net.HttpWebRequest req = System.Net.HttpWebRequest.Create
("http://localhost/webscratch/webform1.aspx") as System.Net.HttpWebRequest;
req.Method = "POST";
System.IO.StreamWriter sw = new System.IO.StreamWriter(req.GetRequestStream());
sw.Write(xml.OuterXml);
sw.Close();
System.Net.HttpWebResponse resp = req.GetResponse() as System.Net.HttpWebResponse;
Console.WriteLine (new System.IO.StreamReader(resp.GetResponseStream()).ReadToEnd());
The result was what I expected, with the beginning of the Console output being:
<CustomerInfo><Name>mdoctor</Name><Age>21</Age></CustomerInfo>System.Web.HttpInputStream
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
...
A View Inside My Head
RHPT
Member
255 Points
51 Posts
Re: Converting MSXML Code to C#/.NET
Aug 18, 2005 01:43 PM|LINK
On default.aspx, I have a textbox that I fill with the following XML string and then submit:
<myFields><txt_name>adsf</txt_name><gender_buttons>Male</gender_buttons><birthday>2005-08-17</birthday><spam_me>true</spam_me></myFields>
XmlDocument doc = new XmlDocument();On my code behind page, I have the following code:
doc.LoadXml(Request.InputStream.ToString());
doc.Save("C:\\Inetpub\\wwwroot\\RX2\\test.xml");
When I debug into the code, Request.InputStream.ToString() returns "System.Web.HttpInputStream".
y2kinfos
Member
7 Points
2 Posts
Re: Converting MSXML Code to C#/.NET
Sep 27, 2005 08:27 PM|LINK
i too have the same problem ...please help me if you got a solution.... my senario is something like this
VB6-FORM file :
Dim objWinHTTP As New WinHTTP.WinHttpRequest
Private Sub Form_Load()
Dim strURL As String
Dim strXML As String
Dim oDom As New MSXML2.DOMDocument40
oDom.Load (App.Path & "/xml_request_ini.xml")
strXML = oDom.xml
strURL = "http://localhost/XML_App_ini/Response_config.aspx"
'strURL = "http://localhost/XML_App_ini/getINIKeys.asp"
With objWinHTTP
.Open "POST", strURL, False
.SetRequestHeader "Content-type", "text/xml"
.Send strXML
.WaitForResponse
getserverINIKeys = objWinHTTP.ResponseText
End With
Set objWinHTTP = Nothing
End Sub
my aspx file :
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strResponseXML As String
Dim obj As New WinHttp.WinHttpRequest Dim objXMLDOM As New MSXML2.DOMDocument Dim strRequestXMLobjXMLDOM.load(Request)
strRequestXML = objXMLDOM.xml
If strRequestXML <> "" Thenobj_RespFill =
New Resp_fillstrResponseXML = "XML Has Values and the values are " & vbCrLf & strRequestXML
ElsestrResponseXML = "XML string is Empty"
End IfResponse.Write(strResponseXML)
obj_RespFill =
NothingobjXMLDOM =
Nothing End Subplease help ....thanks in advance