Solved

Richtext in a SOAP request

Posted on 2010-11-18
4
725 Views
Last Modified: 2012-05-10
Soap webservice, referenced using a .net 3.5 service reference

Text Encoding is utf-8

The field type is a string

<s:element minOccurs="0" maxOccurs="1" name="Content" type="s:string" />

When I try to post richtext (hexadecimal characters) in the string property, the XML breaks.

System.Web.Services.Asmx Error: 0 : Exception Details:
System.Web.Services.Protocols.SoapException: Server was unable to read request. ---> System.InvalidOperationException: There is an error in XML document (1, 13434). ---> System.Xml.XmlException: ' ', hexadecimal value 0x0B, is an invalid character. Line 1, position 13434.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
etc.....

I have tried SecurityElement.Escape, HTMLEncode plus a few other encoding methods to no avail.

Do you have any suggestions?

Is there any way to force a property to use CDATA in the XML request/responses?

I would prefer not to have to manually handle this at each end point.

Thanks in advance


0
Comment
Question by:hamishd
[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
4 Comments
 
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 34186059
0
 
LVL 1

Accepted Solution

by:
mmahdi earned 500 total points
ID: 34197691
Your best option would be to convert your RTF content to base64 string before inserting it into your xml element as base64 is xml friendly. And since the Convert.ToBase64String only takes a byte array as parameter you would need to convert first the RTF content into byte[].

//the RichTextBox control uses utf-16 encoding
//to convert to a byte array you can use ...
byte[] content = System.Text.UnicodeEncoding.Unicode.GetBytes(richTextBox1.Text);

//now convert to base64 string
string rtf = Convert.ToBase64String(content);

//insert the rtf value into your xml.
.....


//To decode your xml back to a new rtf you need to read the node value
string rtf = xmldocument.documentElement.node[0]
//convert from base64 to byte[] then from byte[] to str
richTextBox2.Text = System.Text.UnicodeEncoding.Unicode.GetString(Convert.FromBase64String(s));
0
 
LVL 19

Expert Comment

by:Amandeep Singh Bhullar
ID: 34440998
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

734 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