Solved

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

Posted on 2012-03-19
5
1,019 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 1

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 1

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 1

Author Closing Comment

by:Starr Duskk
ID: 37762384
found solution.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

895 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now