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. Advertisements

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. roni
    Replies:
    0
    Views:
    643
  2. sim.sim
    Replies:
    18
    Views:
    2,716
    Maksim Kasimov
    May 25, 2007
  3. dgleeson422111

    Consuming local web service - ok, remote web service -problem?

    dgleeson422111, Jan 26, 2010, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    1,094
    dgleeson422111
    Jan 26, 2010
  4. Scott Baierl
    Replies:
    1
    Views:
    479
    Scott Baierl
    Jul 29, 2006
  5. Leo Violette
    Replies:
    0
    Views:
    1,317
    Leo Violette
    Apr 17, 2009
  6. Redhot
    Replies:
    0
    Views:
    898
    Redhot
    Jul 18, 2009
  7. durumdara
    Replies:
    3
    Views:
    792
    Stefan Behnel
    Dec 2, 2011
  8. johannes falcone
    Replies:
    2
    Views:
    210
    Kevin Walzer
    Feb 1, 2014
Loading...