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

Discussion in 'ASP .Net' started by Jeff Johnson, Jul 1, 2009.

  1. Jeff Johnson

    Jeff Johnson Guest

    [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.
    Jeff Johnson, Jul 1, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jack Wright

    Problem in CRLF in multiline fields

    Jack Wright, Apr 20, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    381
    Jack Wright
    Apr 21, 2004
  2. sim.sim
    Replies:
    18
    Views:
    1,998
    Maksim Kasimov
    May 25, 2007
  3. sim.sim
    Replies:
    0
    Views:
    468
    sim.sim
    May 22, 2007
  4. durumdara
    Replies:
    3
    Views:
    557
    Stefan Behnel
    Dec 2, 2011
  5. johannes falcone
    Replies:
    2
    Views:
    64
    Kevin Walzer
    Feb 1, 2014
Loading...

Share This Page