Avatar of Starr Duskk
Starr Duskk
Flag for United States of America asked on

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

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!
WCFASP.NET

Avatar of undefined
Last Comment
Starr Duskk

8/22/2022 - Mon
Bob Learned

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.
Starr Duskk

ASKER
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);
SOLUTION
Bob Learned

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Starr Duskk

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Starr Duskk

ASKER
found solution.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck