• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 751
  • Last Modified:

Richtext in a SOAP request

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
hamishd
Asked:
hamishd
1 Solution
 
Kumaraswamy RCommented:
0
 
mmahdiCommented:
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
 
Amandeep Singh BhullarCommented:
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now