Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / May 2005

Tip: Looking for answers? Try searching our database.

CR char eliminated

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
NormD - 26 May 2005 15:55 GMT
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] - 27 May 2005 04:12 GMT
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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.