CR char eliminated

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • NormD

    #1

    CR char eliminated

    I'm sending a string (xml string) to web service as a parameter. One of the
    tags in the xml string is the address field and the values of this tag have
    LF + CR chars. When I receive the string in the web service method the values
    have only the LF chars.
    What's happening here?
  • [MSFT]

    #2
    RE: CR char eliminated

    Hello,

    Before sending to the web service class, the paramter string will be
    encoded and decoded, and the CR was lost during the procedure. To get
    around the issue, you can consider following ways;

    1. When get the string in web service, search for LF in the string and
    replace with LF+CR.
    2. Before send the string to web service, change its encoding to Unicode.
    For example:

    Encoding ascii = Encoding.ASCII;
    Encoding unicode = Encoding.Unicod e;

    byte[] asciiBytes = ascii.GetBytes( MyString);
    byte[] unicodeBytes = Encoding.Conver t(ascii,unicode , asciiBytes);

    char[] unicodeChars = new char[unicode.GetChar Count(unicodeBy tes, 0,
    unicodeBytes.Le ngth)];
    unicode.GetChar s(unicodeBytes, 0, unicodeBytes.Le ngth, unicodeChars, 0);
    string unicodeString = new string(unicodeC hars)

    In this way, the string will be pass in Unicode encoding the CR won't be
    lost.

    On Web service side, we can use the Uncode string directly, or convert it
    to ASCII back:

    Encoding ascii = Encoding.ASCII;
    Encoding unicode = Encoding.Unicod e;

    byte[] unicodeBytes = unicode.GetByte s(MyString);
    byte[] asciiBytes = Encoding.Conver t(unicode, ascii, unicodeBytes);

    char[] asciiChars = new char[ascii.GetCharCo unt(asciiBytes, 0,
    asciiBytes.Leng th)];
    ascii.GetChars( asciiBytes, 0, asciiBytes.Leng th, asciiChars, 0);
    string asciiString = new string(asciiCha rs);

    Hope this help,

    Luke

    Comment

    • [MSFT]

      #3
      RE: CR char eliminated

      Hello,

      Before sending to the web service class, the paramter string will be
      encoded and decoded, and the CR was lost during the procedure. To get
      around the issue, you can consider following ways;

      1. When get the string in web service, search for LF in the string and
      replace with LF+CR.
      2. Before send the string to web service, change its encoding to Unicode.
      For example:

      Encoding ascii = Encoding.ASCII;
      Encoding unicode = Encoding.Unicod e;

      byte[] asciiBytes = ascii.GetBytes( MyString);
      byte[] unicodeBytes = Encoding.Conver t(ascii,unicode , asciiBytes);

      char[] unicodeChars = new char[unicode.GetChar Count(unicodeBy tes, 0,
      unicodeBytes.Le ngth)];
      unicode.GetChar s(unicodeBytes, 0, unicodeBytes.Le ngth, unicodeChars, 0);
      string unicodeString = new string(unicodeC hars)

      In this way, the string will be pass in Unicode encoding the CR won't be
      lost.

      On Web service side, we can use the Uncode string directly, or convert it
      to ASCII back:

      Encoding ascii = Encoding.ASCII;
      Encoding unicode = Encoding.Unicod e;

      byte[] unicodeBytes = unicode.GetByte s(MyString);
      byte[] asciiBytes = Encoding.Conver t(unicode, ascii, unicodeBytes);

      char[] asciiChars = new char[ascii.GetCharCo unt(asciiBytes, 0,
      asciiBytes.Leng th)];
      ascii.GetChars( asciiBytes, 0, asciiBytes.Leng th, asciiChars, 0);
      string asciiString = new string(asciiCha rs);

      Hope this help,

      Luke

      Comment

      • NormD

        #4
        RE: CR char eliminated

        Thanks for your response.
        It looks to me that this is a bug, I don't understand the rational to change
        lfcr to lf otherwise.

        "[MSFT]" wrote:
        [color=blue]
        > Hello,
        >
        > Before sending to the web service class, the paramter string will be
        > encoded and decoded, and the CR was lost during the procedure. To get
        > around the issue, you can consider following ways;
        >
        > 1. When get the string in web service, search for LF in the string and
        > replace with LF+CR.
        > 2. Before send the string to web service, change its encoding to Unicode.
        > For example:
        >
        > Encoding ascii = Encoding.ASCII;
        > Encoding unicode = Encoding.Unicod e;
        >
        > byte[] asciiBytes = ascii.GetBytes( MyString);
        > byte[] unicodeBytes = Encoding.Conver t(ascii,unicode , asciiBytes);
        >
        > char[] unicodeChars = new char[unicode.GetChar Count(unicodeBy tes, 0,
        > unicodeBytes.Le ngth)];
        > unicode.GetChar s(unicodeBytes, 0, unicodeBytes.Le ngth, unicodeChars, 0);
        > string unicodeString = new string(unicodeC hars)
        >
        > In this way, the string will be pass in Unicode encoding the CR won't be
        > lost.
        >
        > On Web service side, we can use the Uncode string directly, or convert it
        > to ASCII back:
        >
        > Encoding ascii = Encoding.ASCII;
        > Encoding unicode = Encoding.Unicod e;
        >
        > byte[] unicodeBytes = unicode.GetByte s(MyString);
        > byte[] asciiBytes = Encoding.Conver t(unicode, ascii, unicodeBytes);
        >
        > char[] asciiChars = new char[ascii.GetCharCo unt(asciiBytes, 0,
        > asciiBytes.Leng th)];
        > ascii.GetChars( asciiBytes, 0, asciiBytes.Leng th, asciiChars, 0);
        > string asciiString = new string(asciiCha rs);
        >
        > Hope this help,
        >
        > Luke[/color]

        Comment

        • NormD

          #5
          RE: CR char eliminated

          Thanks for your response.
          It looks to me that this is a bug, I don't understand the rational to change
          lfcr to lf otherwise.

          "[MSFT]" wrote:
          [color=blue]
          > Hello,
          >
          > Before sending to the web service class, the paramter string will be
          > encoded and decoded, and the CR was lost during the procedure. To get
          > around the issue, you can consider following ways;
          >
          > 1. When get the string in web service, search for LF in the string and
          > replace with LF+CR.
          > 2. Before send the string to web service, change its encoding to Unicode.
          > For example:
          >
          > Encoding ascii = Encoding.ASCII;
          > Encoding unicode = Encoding.Unicod e;
          >
          > byte[] asciiBytes = ascii.GetBytes( MyString);
          > byte[] unicodeBytes = Encoding.Conver t(ascii,unicode , asciiBytes);
          >
          > char[] unicodeChars = new char[unicode.GetChar Count(unicodeBy tes, 0,
          > unicodeBytes.Le ngth)];
          > unicode.GetChar s(unicodeBytes, 0, unicodeBytes.Le ngth, unicodeChars, 0);
          > string unicodeString = new string(unicodeC hars)
          >
          > In this way, the string will be pass in Unicode encoding the CR won't be
          > lost.
          >
          > On Web service side, we can use the Uncode string directly, or convert it
          > to ASCII back:
          >
          > Encoding ascii = Encoding.ASCII;
          > Encoding unicode = Encoding.Unicod e;
          >
          > byte[] unicodeBytes = unicode.GetByte s(MyString);
          > byte[] asciiBytes = Encoding.Conver t(unicode, ascii, unicodeBytes);
          >
          > char[] asciiChars = new char[ascii.GetCharCo unt(asciiBytes, 0,
          > asciiBytes.Leng th)];
          > ascii.GetChars( asciiBytes, 0, asciiBytes.Leng th, asciiChars, 0);
          > string asciiString = new string(asciiCha rs);
          >
          > Hope this help,
          >
          > Luke[/color]

          Comment

          • [MSFT]

            #6
            RE: CR char eliminated

            This is not only with Web service, but also all XML processor which treat
            the character sequence Carriage Return-Line Feed (CRLF) like single CR or
            LF characters. All are reported as a single LF character. XML is
            cross-platform standard, this is designed for the compatibility with
            others, such as Unix.

            Hope this help,

            Luke

            Comment

            • [MSFT]

              #7
              RE: CR char eliminated

              This is not only with Web service, but also all XML processor which treat
              the character sequence Carriage Return-Line Feed (CRLF) like single CR or
              LF characters. All are reported as a single LF character. XML is
              cross-platform standard, this is designed for the compatibility with
              others, such as Unix.

              Hope this help,

              Luke

              Comment

              Working...