Solved

HttpWebRequest.GetResponse() returning Envelope and [CData and Encoded values

Posted on 2012-03-19
5
1,030 Views
Last Modified: 2012-06-21
I'm am using the HttpWebRequest.GetResponse()  to get an XML file from a client.

The client XML is returned with everything decoded.
The client is returning the Envelope.
The client is returning part of the data inside a [CDATA wrapper. It returns several required elements, then it returns a [CDATA with the remaining elements.

I want to deserialize the data eventually.

If I try to write to an XMLDocument it errors:
XmlDocument xmlResults = new XmlDocument();
                            xmlResults.XmlResolver = null;
                            xmlResults.LoadXml(soapResponseMsg);


I have tried stripping out the Envelope.
Decoding the &lt; and &gt; back to < and >.

But when I deserialize the raw data, it doesn't find the values between the [CDATA so it doesn't deserialize anything within that.

Then I tried stripping out the CDATA, but then it errors, because the client has data within the elements with < and > symbols, so then I get an error:

>Data at the root level is invalid. Line 1, position 1."

<class>GVWR<26001</class>

So it thinks the < symbol above is a command!

I have tried all kinds of encoding tricks.
request.ContentType = "text/xml;charset=\"utf-8\""; // add escaped
request.Accept = "text/xml";

and

Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
using (StreamReader reader = new StreamReader(response.GetResponseStream(), encode))

... hoping there is some setting that will retrieve the XML data with the < > as they should be, but leave the body &lt; as it should.

Is there something?

Thanks!
0
Comment
Question by:Starr Duskk
  • 3
  • 2
5 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 37741897
I don't understand what you have tried?  If you have 3.5 or higher, then you should be able to use LINQ-to-XML, which is the XDocument class.  You should be able to use the original XML, and parse out what you need.
0
 
LVL 2

Author Comment

by:Starr Duskk
ID: 37741978
I have to save this as a string and store it in the database as a blob. Then a later web service will retrieve the blob and deserialize the data.

But first before it saves to the database, it tries to write to an xmldocument, to make sure it is valid XML, and it fails because of the &lt;, the envelope and the CData wrapper embedded within the body of the XML.

XmlDocument xmlResults = new XmlDocument();
                            xmlResults.XmlResolver = null;
                            xmlResults.LoadXml(soapResponseMsg);
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 500 total points
ID: 37741985
Can you show me an example of the XML, and the validation errors, please?
0
 
LVL 2

Accepted Solution

by:
Starr Duskk earned 0 total points
ID: 37742904
I found the solution.

I use the SoapEnvelope class to retrieve the envelope, then load the envelope body into an XmlDocument. Then I strip out the <![CDATA[ and its closer.

Thanks!
0
 
LVL 2

Author Closing Comment

by:Starr Duskk
ID: 37762384
found solution.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question