.NETGURU
Translation of newline characters when transmitted via web service
Messages   Related Types
This message was discovered on microsoft.public.dotnet.distributed_apps.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

news.microsoft.com
We have noticed that a CR LF transmitted in a string to from a web service
will be replaced with the (unix style) single LF. This translation is not
undone on the client side. (Both client and server are .Net)

Before we go and manually undo the translation on the client side is there
some setting on the web reference or the WSDL file that would take care of
this? Adding a replace() on the client side call seems like a bit of a
hack.

Any ideas?

Reply to this message...
 
    
DanielS (VIP)
Are you not using the "\r\n" style for CRLFs embedded in strings?
This works for me:

[WebMethod]
public string MyMethod()
{
return "This is the first line.\r\nAnd this is the second one."
}

This will always preserve the line feed.

"news.microsoft.com" wrote:

[Original message clipped]

Reply to this message...
 
    
Don McNamara
Hrmm... What version of .Net are you using? We have tried this several
different ways and have had no luck.

When the client side deserializes the data, the \r\n is replaced with just a
\n (unless the data is in a dataset)

"DanielS" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
DanielS (VIP)
Yes, you're right :( the \r gets eaten by .NET
I did not notice it because if you happen to display the string in a
MessageBox, for example, you don't notice the difference.

But, there are some solutions to that.

1) If you really, really need that \r\n pair try to use the @-quoting. Like
this:

[WebMethod]
public string MyMethod()
{
return @"This is the first line.\r\nAnd this is the second one.";
}
The only problem here is that you now get the "\r\n" ad literam (as
literals of the string). So far I don't know how can you revert it back...

2) You can write the webmethod to return an ArrayList in the web service;
suppose we read the strings from an xml document:

[WebMethod]
public ArrayList GetStrings()
{

ArrayList list = new ArrayList();
list.Add("This is line 1.");
list.Add("This is line 2.");
return list;

}

and, on the client side:
[...]
WebRefFileService.FileService wfs = new WebRefFileService.FileService();
ArrayList al = new ArrayList(wfs.GetStrings());
etc.

And that's where my knowledge stops :)
Regards,
Dan

"Don McNamara" wrote:

[Original message clipped]

Reply to this message...
 
 
System.Collections.ArrayList
System.Windows.Forms.MessageBox




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification