By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,953 Members | 1,438 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,953 IT Pros & Developers. It's quick & easy.

/r/n (13-10) (carriage return - line feed) in web services

P: n/a
Hi,
A few days go I fiund iut that the xmlserializer strips away /r/n out during
deserialization (and just leave /n)
... I found out that you can resolve this problem using the deserialize
overlaod that takes an xmltextreader instead of a stream ..

However when it's time to Web Services you have no such a control over the
deserialization phase AND I found out that WS strips out /r/n (an leave /n)
... I understand there are some XMl specs related to this .. however . what
one should do to have a /r/n sequence into a string property of his own
custom object ?

I saw that writing /r/n as unicode numbers does work .. however this implies
writing some custom soap extension / http module to replace 0d,0a sequences
to their unicode equivalence ( ..and .. btw .. how do I avoid to mix up
binary data eventually transmitted that contains this sequence ?) .. are
there better way to solve this ?

Any suggestion is appreciated.
thank a lot
Enrico Sabbadin

Nov 13 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I've done a soap extension that replace /r/n with 
 and 

it looks like working .. if someone is interested

(it hooks into client and server SoapMessageStage.AfterSerialize event)
....

protected void CopyFromToEx(Stream from, Stream to) {
TextReader reader = new StreamReader(from);
TextWriter writer = new StreamWriter(to);
char[] l_b = new char[1];
int i = 0;
while (reader.Read(l_b,0,1)!=0) {
if (System.Text.Encoding.UTF8.GetBytes(l_b)[0] == 13 )
writer.Write("
");
else if (System.Text.Encoding.UTF8.GetBytes(l_b)[0] == 10)
writer.Write("
");
else
writer.Write(l_b);

i++;
}
writer.Flush();
}

........
is there a better way ?

"Enrico Sabbadin" <xwrote in message
news:uq**************@TK2MSFTNGP02.phx.gbl...
Hi,
A few days go I fiund iut that the xmlserializer strips away /r/n out
during deserialization (and just leave /n)
.. I found out that you can resolve this problem using the deserialize
overlaod that takes an xmltextreader instead of a stream ..

However when it's time to Web Services you have no such a control over the
deserialization phase AND I found out that WS strips out /r/n (an leave
/n) .. I understand there are some XMl specs related to this .. however .
what one should do to have a /r/n sequence into a string property of his
own custom object ?

I saw that writing /r/n as unicode numbers does work .. however this
implies writing some custom soap extension / http module to replace 0d,0a
sequences to their unicode equivalence ( ..and .. btw .. how do I avoid to
mix up binary data eventually transmitted that contains this sequence ?)
.. are there better way to solve this ?

Any suggestion is appreciated.
thank a lot
Enrico Sabbadin
Nov 13 '06 #2

P: n/a
Hi Enrico,

This will work. I just wanted to add a note that you don't have to use the
System.Text.Encoding.UTF8.GetBytes because the \r and \n characters have the
same integer value in UTF-8 and UTF-16. You can directly test it, such as:

if (l_b[0] == 13 )

Also the \n character does not have to be escaped since it is not going to
get stripped out by the XML normalization (unless it is in an attribute
value).

Hope that helps.

Thanks,
-Helena Kotas

"Enrico Sabbadin" wrote:
I've done a soap extension that replace /r/n with
and
it looks like working .. if someone is interested

(it hooks into client and server SoapMessageStage.AfterSerialize event)
....

protected void CopyFromToEx(Stream from, Stream to) {
TextReader reader = new StreamReader(from);
TextWriter writer = new StreamWriter(to);
char[] l_b = new char[1];
int i = 0;
while (reader.Read(l_b,0,1)!=0) {
if (System.Text.Encoding.UTF8.GetBytes(l_b)[0] == 13 )
writer.Write("
");
else if (System.Text.Encoding.UTF8.GetBytes(l_b)[0] == 10)
writer.Write("
");
else
writer.Write(l_b);

i++;
}
writer.Flush();
}

........
is there a better way ?

"Enrico Sabbadin" <xwrote in message
news:uq**************@TK2MSFTNGP02.phx.gbl...
Hi,
A few days go I fiund iut that the xmlserializer strips away /r/n out
during deserialization (and just leave /n)
.. I found out that you can resolve this problem using the deserialize
overlaod that takes an xmltextreader instead of a stream ..

However when it's time to Web Services you have no such a control over the
deserialization phase AND I found out that WS strips out /r/n (an leave
/n) .. I understand there are some XMl specs related to this .. however .
what one should do to have a /r/n sequence into a string property of his
own custom object ?

I saw that writing /r/n as unicode numbers does work .. however this
implies writing some custom soap extension / http module to replace 0d,0a
sequences to their unicode equivalence ( ..and .. btw .. how do I avoid to
mix up binary data eventually transmitted that contains this sequence ?)
.. are there better way to solve this ?

Any suggestion is appreciated.
thank a lot
Enrico Sabbadin

Nov 15 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.