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?
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,
Luke
NormD - 27 May 2005 22:26 GMT
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.
> Hello,
>
[quoted text clipped - 38 lines]
>
> Luke
[MSFT] - 30 May 2005 08:05 GMT
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