Reading XML string from HttpRequest

  • Thread starter Thread starter Daniel Rimmelzwaan
  • Start date Start date
D

Daniel Rimmelzwaan

I am having trouble getting the XML out of an HttpRequest object.

I am sending the XML from biztalk into my aspx page, after which I want to
take the XML out of it and process it using a MSXML.DOMDocument. I
understand that in the Request object, it is stored as a binary, and I can't
figure out how to translate it into a text string.

Do I need to read it into a byte variable and then move it to the
DOMDocument, or is there a method I can use to read it directly from the
Request? Maybe there is a better way to do this using one of the .NET
namespaces.

The code example that I am trying to translate into C# is using an
ADODB.Stream object and just changes the type from binary to text, after
which it can read it. The problem is that I don't want to have to register
all these 'old' dll's to make the ADODB work, there has to be a way to do
this in the .NET framework.

Thanks,
Daniel.
 
Daniel said:
I am having trouble getting the XML out of an HttpRequest object.

I am sending the XML from biztalk into my aspx page, after which I want to
take the XML out of it and process it using a MSXML.DOMDocument. I
understand that in the Request object, it is stored as a binary, and I can't
figure out how to translate it into a text string.

Do I need to read it into a byte variable and then move it to the
DOMDocument, or is there a method I can use to read it directly from the
Request? Maybe there is a better way to do this using one of the .NET
namespaces.

The code example that I am trying to translate into C# is using an
ADODB.Stream object and just changes the type from binary to text, after
which it can read it. The problem is that I don't want to have to register
all these 'old' dll's to make the ADODB work, there has to be a way to do
this in the .NET framework.

Thanks,
Daniel.

How is that XML document coming in? Is this as a value for a param? or
is this the only thing in the Post? If its the only thing coming in, you
can wrap the HttpRequest.InputStream with a StreamReader and use
ReadToEnd() on that StreamReader. That should get you the whole thing in
a "string".
Is this what you are looking for?
 
Girish Bharadwaj said:
How is that XML document coming in? Is this as a value for a param? or
is this the only thing in the Post? If its the only thing coming in, you
can wrap the HttpRequest.InputStream with a StreamReader and use
ReadToEnd() on that StreamReader. That should get you the whole thing in
a "string".
Is this what you are looking for?

The XML is passed from BizTalk into my aspx page, so I am assuming that is
what is in the HttpRequest. Using the StreamReader, it still shows the
binary stream, not the text itself. Here's the code I have:
System.IO.StreamReader MyReader = new System.IO.StreamReader
(Request.InputStream,System.Text.Encoding.Unicode,false);

string MyDoc = MyReader.ReadToEnd().ToString();

Response.Write(MyDoc);

The result is a big page of binary characters, not the XML that is sent to
the aspx page. It also does that when I don't have the ToString at the end
of the statement.
 
Daniel said:
The XML is passed from BizTalk into my aspx page, so I am assuming that is
what is in the HttpRequest. Using the StreamReader, it still shows the
binary stream, not the text itself. Here's the code I have:
System.IO.StreamReader MyReader = new System.IO.StreamReader
(Request.InputStream,System.Text.Encoding.Unicode,false);

string MyDoc = MyReader.ReadToEnd().ToString();

Response.Write(MyDoc);

The result is a big page of binary characters, not the XML that is sent to
the aspx page. It also does that when I don't have the ToString at the end
of the statement.
Why dont you try allowing the StreamReader to recognize the byte order
and let it decide the encoding.. i.e. Just pass the inputstream into the
streamreader..
What happens then?
 
Daniel Rimmelzwaan said:
I am having trouble getting the XML out of an HttpRequest object.

I am sending the XML from biztalk into my aspx page, after which I
want to take the XML out of it and process it using a
MSXML.DOMDocument. I understand that in the Request object, it is
stored as a binary, and I can't figure out how to translate it into
a text string.

Do I need to read it into a byte variable and then move it to the
DOMDocument, or is there a method I can use to read it directly from
the Request? Maybe there is a better way to do this using one of the
.NET namespaces.

The code example that I am trying to translate into C# is using an
ADODB.Stream object and just changes the type from binary to text,
after which it can read it. The problem is that I don't want to have
to register all these 'old' dll's to make the ADODB work, there has
to be a way to do this in the .NET framework.

Well, leaving behind all that old fashioned stuff such as MSXML, you can
basically do what you want in two lines of code:

// assuming we're in a code behind class or ASP.NET page
XmlDocument doc = new XmlDocument();
doc.Load(Request.Stream);

Now, you can manipulate the XML document using XmlDocument DOM API.

Cheers,
 
Back
Top