?
Solved

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

Posted on 2012-03-19
5
Medium Priority
?
1,039 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

762 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