Solved

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

Posted on 2012-03-19
5
1,015 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:BobCSD
  • 3
  • 2
5 Comments
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
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:BobCSD
Comment Utility
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
Comment Utility
Can you show me an example of the XML, and the validation errors, please?
0
 
LVL 1

Accepted Solution

by:
BobCSD earned 0 total points
Comment Utility
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:BobCSD
Comment Utility
found solution.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now