all groups > dotnet web services > may 2005 >
You're in the

dotnet web services

group:

CR char eliminated



RE: CR char eliminated lukezhan NO[at]SPAM online.microsoft.com
5/26/2005 12:00:00 AM
dotnet web services: 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.Unicode;

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

char[] unicodeChars = new char[unicode.GetCharCount(unicodeBytes, 0,
unicodeBytes.Length)];
unicode.GetChars(unicodeBytes, 0, unicodeBytes.Length, unicodeChars, 0);
string unicodeString = new string(unicodeChars)

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.Unicode;

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

char[] asciiChars = new char[ascii.GetCharCount(asciiBytes, 0,
asciiBytes.Length)];
ascii.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
string asciiString = new string(asciiChars);

Hope this help,

CR char eliminated NormD
5/26/2005 7:55:22 AM
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.
RE: CR char eliminated NormD
5/27/2005 2:26:02 PM
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.

[quoted text, click to view]
RE: CR char eliminated lukezhan NO[at]SPAM online.microsoft.com
5/30/2005 7:05:14 AM
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,

AddThis Social Bookmark Button