Having a problem with CRLF in XML going to a Web service

  • Thread starter Thread starter Jeff Johnson
  • Start date Start date
J

Jeff Johnson

[If there's a better group to post this in, please tell me, but the
..webservices and .xml groups are pretty bare, so I chose this one.]

I'm sending an object to a Web service which has a string property that
could contain CRLFs. When the proxy object is rehydrated on the service side
int a "real" object, all CRLFs in the string are converted to LFs. It is
possible that the string could contain legitimate bare LFs and therefore I
don't want to do a blanket LF --> CRLF replacement, instead I want to find a
method to preserve every character in the string as-is.

My first thought was to implement IXmlSerializable and wrap this property in
a CDATA section, as I naively thought the purpose of CDATA was to preserve
everything. After loads of effort to get this working, the final result was
that I STILL lost the CRs.

My next fallback was to Base64 the string. This is working fine, but it's a
little awkward to use since now the property is no longer a string but a
class which wraps that string, and it makes using the property a little less
natural. So I have some questions:

1) Is there a way to preserve every character (by which I mainly mean
whitespace) in XML besides applying some form of encoding to the string?

2) If encoding (Base64 or BinHex) is the only answer, are there any
attributes I'm missing which will instruct the serializer to encode and
decode a string without my having to step in via IXmlSerializer and do it
myself? To be able to decorate a string property with something like

[XmlEncodeAs(Method=Base64)]

would be spectacular.
 
Back
Top