text gets destroyed

  • Thread starter Thread starter Jimmy
  • Start date Start date
J

Jimmy

Hey

Im writing text in a multiline textbox. Im pressing a button wich results in
a call to a web service that saves the data in MS SQL Server as ntext. At
another point in my application i do a select on this ntext field and then i
want that text to go into the same multiline textbox.

My problem is that when i write out the text it puts out a lot of squares in
the text where there should be a new line.
textBox.Text = DS.Tables[0].Rows[0]["ntextfield"].ToString();

But if i instead write out the text in a messagebox everything looks just
fine.
MessageBox.Show(textBox.Text);

What am i doing wrong here?

Please help.
 
Make sure that the textbox where you put the text retrieved from the web
service is multiline. If this does not help, check that the text received
back still has "\r\n" as line terminators and that they are not reduced to
"\n"
 
It is multiline.

I dont know how to check wether it is "\r\n" or just "\n". Can you give me
any hints on that?

Thanks so far :)

--


Jimmy
Alex Feinman said:
Make sure that the textbox where you put the text retrieved from the web
service is multiline. If this does not help, check that the text received
back still has "\r\n" as line terminators and that they are not reduced to
"\n"

--
Alex Feinman
---
Visit http://www.opennetcf.org
Jimmy said:
Hey

Im writing text in a multiline textbox. Im pressing a button wich results
in
a call to a web service that saves the data in MS SQL Server as ntext. At
another point in my application i do a select on this ntext field and then
i
want that text to go into the same multiline textbox.

My problem is that when i write out the text it puts out a lot of squares
in
the text where there should be a new line.
textBox.Text = DS.Tables[0].Rows[0]["ntextfield"].ToString();

But if i instead write out the text in a messagebox everything looks just
fine.
MessageBox.Show(textBox.Text);

What am i doing wrong here?

Please help.
 
Add to your code
byte[] bytes = System.Text.Encoding.Unicode.GetBytes(s); // s is your string

and examine the bytes in the debugger. Check if the line breaks are 00 0a or
00 0d 00 0a



Alrternatively you can output the hex string using

MessageBox.Show(BitConverter.ToString(System.Text.Encoding.Unicode.GetBytes(s)));


--
Alex Feinman
---
Visit http://www.opennetcf.org
Jimmy said:
It is multiline.

I dont know how to check wether it is "\r\n" or just "\n". Can you give me
any hints on that?

Thanks so far :)

--


Jimmy
Alex Feinman said:
Make sure that the textbox where you put the text retrieved from the web
service is multiline. If this does not help, check that the text received
back still has "\r\n" as line terminators and that they are not reduced
to
"\n"

--
Alex Feinman
---
Visit http://www.opennetcf.org
Jimmy said:
Hey

Im writing text in a multiline textbox. Im pressing a button wich results
in
a call to a web service that saves the data in MS SQL Server as ntext. At
another point in my application i do a select on this ntext field and then
i
want that text to go into the same multiline textbox.

My problem is that when i write out the text it puts out a lot of squares
in
the text where there should be a new line.
textBox.Text = DS.Tables[0].Rows[0]["ntextfield"].ToString();

But if i instead write out the text in a messagebox everything looks just
fine.
MessageBox.Show(textBox.Text);

What am i doing wrong here?

Please help.
 
Thanks :)

Used the MessageBox.Show instead of the debugger. Found that easier :)

Ok, so now i can see that it actually only writes the "\n".

I can update this field from the web wich i use to input test data. So
everytime i want to start over i just fill in the testdata from there. After
having done that i start the application on my pocket PC again. When i load
these values it actually says "\r\n". Then i save the exact same data,
without touching anything, from my Pocket PC. When i reload the values into
my Pocket PC application it only says "\n". Now isnt that weird?

Do you, or anybody else, know why this is happening?

It seems like its not saving the "\r"-part of my text???

Thanks so far for your help. Really appreciate it. :)

--


Jimmy
Alex Feinman said:
Add to your code
byte[] bytes = System.Text.Encoding.Unicode.GetBytes(s); // s is your string

and examine the bytes in the debugger. Check if the line breaks are 00 0a or
00 0d 00 0a



Alrternatively you can output the hex string using

MessageBox.Show(BitConverter.ToString(System.Text.Encoding.Unicode.GetBytes(
s)));


--
Alex Feinman
---
Visit http://www.opennetcf.org
Jimmy said:
It is multiline.

I dont know how to check wether it is "\r\n" or just "\n". Can you give me
any hints on that?

Thanks so far :)

--


Jimmy
Alex Feinman said:
Make sure that the textbox where you put the text retrieved from the web
service is multiline. If this does not help, check that the text received
back still has "\r\n" as line terminators and that they are not reduced
to
"\n"

--
Alex Feinman
---
Visit http://www.opennetcf.org
Hey

Im writing text in a multiline textbox. Im pressing a button wich results
in
a call to a web service that saves the data in MS SQL Server as
ntext.
At
another point in my application i do a select on this ntext field and then
i
want that text to go into the same multiline textbox.

My problem is that when i write out the text it puts out a lot of squares
in
the text where there should be a new line.
textBox.Text = DS.Tables[0].Rows[0]["ntextfield"].ToString();

But if i instead write out the text in a messagebox everything looks just
fine.
MessageBox.Show(textBox.Text);

What am i doing wrong here?

Please help.
 
What does your web service look like?

--
Alex Feinman
---
Visit http://www.opennetcf.org
Jimmy said:
Thanks :)

Used the MessageBox.Show instead of the debugger. Found that easier :)

Ok, so now i can see that it actually only writes the "\n".

I can update this field from the web wich i use to input test data. So
everytime i want to start over i just fill in the testdata from there.
After
having done that i start the application on my pocket PC again. When i
load
these values it actually says "\r\n". Then i save the exact same data,
without touching anything, from my Pocket PC. When i reload the values
into
my Pocket PC application it only says "\n". Now isnt that weird?

Do you, or anybody else, know why this is happening?

It seems like its not saving the "\r"-part of my text???

Thanks so far for your help. Really appreciate it. :)

--


Jimmy
Alex Feinman said:
Add to your code
byte[] bytes = System.Text.Encoding.Unicode.GetBytes(s); // s is your string

and examine the bytes in the debugger. Check if the line breaks are 00 0a or
00 0d 00 0a



Alrternatively you can output the hex string using

MessageBox.Show(BitConverter.ToString(System.Text.Encoding.Unicode.GetBytes(
s)));


--
Alex Feinman
---
Visit http://www.opennetcf.org
Jimmy said:
It is multiline.

I dont know how to check wether it is "\r\n" or just "\n". Can you give me
any hints on that?

Thanks so far :)

--


Jimmy
"Alex Feinman [MVP]" <[email protected]> skrev i en
meddelelse
Make sure that the textbox where you put the text retrieved from the web
service is multiline. If this does not help, check that the text received
back still has "\r\n" as line terminators and that they are not
reduced
to
"\n"

--
Alex Feinman
---
Visit http://www.opennetcf.org
Hey

Im writing text in a multiline textbox. Im pressing a button wich
results
in
a call to a web service that saves the data in MS SQL Server as ntext.
At
another point in my application i do a select on this ntext field
and
then
i
want that text to go into the same multiline textbox.

My problem is that when i write out the text it puts out a lot of
squares
in
the text where there should be a new line.
textBox.Text = DS.Tables[0].Rows[0]["ntextfield"].ToString();

But if i instead write out the text in a messagebox everything looks
just
fine.
MessageBox.Show(textBox.Text);

What am i doing wrong here?

Please help.
 
Ok.

retVals is a class i use for returning values back to my application.
strConn contains my db connection string.
field3 is the field giving me a headache.

This is the calling line in my application:
....Update_Fields(com_field1.Text, field2.Text,
textBox_field3.Text.Replace(";",":"), field4, field5);

I have tried without the Replace, but as expected it didnt change anything
regarding this :)

Heres the web service
[WebMethod]
public retVals Update_Fields(string field1, string field2, string field3,
short field4, bool field5)
{
SqlConnection Conn = null;
int numrows = 0;
retVals retval = null;
SqlCommand sqlCommand = null;
try
{
retval = new retVals();
Conn = new SqlConnection(strConn);
sqlCommand = new SqlCommand("sp_upd_fields", Conn);
sqlCommand.CommandType = CommandType.StoredProcedure;

SqlParameter param = sqlCommand.Parameters.Add("@field1",
SqlDbType.NVarChar, 10);
param.Direction = ParameterDirection.Input;
param.Value = field1;

param = sqlCommand.Parameters.Add("@field2", SqlDbType.NVarChar,
50);
param.Direction = ParameterDirection.Input;
param.Value = field2;

param = sqlCommand.Parameters.Add("@field3", SqlDbType.NText);
param.Direction = ParameterDirection.Input;
param.Value = field3;

param = sqlCommand.Parameters.Add("@field4", SqlDbType.SmallInt);
param.Direction = ParameterDirection.Input;
param.Value = field4;

param = sqlCommand.Parameters.Add("@field5", SqlDbType.Bit);
param.Direction = ParameterDirection.Input;
param.Value = field5;

Conn.Open();
numrows = sqlCommand.ExecuteNonQuery();
retval.err = 0;
retval.msg = "";
retval.retInt = numrows;
}
catch (Exception e)
{
errHandling err = new errHandling(e, field2, "");
if (retval == null)
retval = new retVals();
retval.err = 1;
retval.msg = "Error in Web Service";
retval.retInt = 0;
}
finally
{
if (Conn != null)
Conn.Close();
}
return retval;
}

--


Jimmy

Alex Feinman said:
What does your web service look like?

--
Alex Feinman
---
Visit http://www.opennetcf.org
Jimmy said:
Thanks :)

Used the MessageBox.Show instead of the debugger. Found that easier :)

Ok, so now i can see that it actually only writes the "\n".

I can update this field from the web wich i use to input test data. So
everytime i want to start over i just fill in the testdata from there.
After
having done that i start the application on my pocket PC again. When i
load
these values it actually says "\r\n". Then i save the exact same data,
without touching anything, from my Pocket PC. When i reload the values
into
my Pocket PC application it only says "\n". Now isnt that weird?

Do you, or anybody else, know why this is happening?

It seems like its not saving the "\r"-part of my text???

Thanks so far for your help. Really appreciate it. :)

--


Jimmy
Alex Feinman said:
Add to your code
byte[] bytes = System.Text.Encoding.Unicode.GetBytes(s); // s is your string

and examine the bytes in the debugger. Check if the line breaks are 00
0a
or
00 0d 00 0a



Alrternatively you can output the hex string using
MessageBox.Show(BitConverter.ToString(System.Text.Encoding.Unicode.GetBytes(
s)));
--
Alex Feinman
---
Visit http://www.opennetcf.org
It is multiline.

I dont know how to check wether it is "\r\n" or just "\n". Can you
give
me
any hints on that?

Thanks so far :)

--


Jimmy
"Alex Feinman [MVP]" <[email protected]> skrev i en
meddelelse
Make sure that the textbox where you put the text retrieved from the web
service is multiline. If this does not help, check that the text received
back still has "\r\n" as line terminators and that they are not
reduced
to
"\n"

--
Alex Feinman
---
Visit http://www.opennetcf.org
Hey

Im writing text in a multiline textbox. Im pressing a button wich
results
in
a call to a web service that saves the data in MS SQL Server as ntext.
At
another point in my application i do a select on this ntext field
and
then
i
want that text to go into the same multiline textbox.

My problem is that when i write out the text it puts out a lot of
squares
in
the text where there should be a new line.
textBox.Text = DS.Tables[0].Rows[0]["ntextfield"].ToString();

But if i instead write out the text in a messagebox everything looks
just
fine.
MessageBox.Show(textBox.Text);

What am i doing wrong here?

Please help.
 
Hey

Tried to do the messagebox trick just before calling the webservice. At that
point the text is ok.

Then i tried to do the messagebox trick in my webservice (well, not exactly
a messagebox, but i wrote it to a filestream). When i do that as the first
thing in my webservice, i can see that it has cut of the "\r". So i guess
the problem is in the transfering of the variable to the webservice.

Now im totally lost.

How do i fix this?

Thanks so far :)

--


Jimmy
Alex Feinman said:
What does your web service look like?

--
Alex Feinman
---
Visit http://www.opennetcf.org
Jimmy said:
Thanks :)

Used the MessageBox.Show instead of the debugger. Found that easier :)

Ok, so now i can see that it actually only writes the "\n".

I can update this field from the web wich i use to input test data. So
everytime i want to start over i just fill in the testdata from there.
After
having done that i start the application on my pocket PC again. When i
load
these values it actually says "\r\n". Then i save the exact same data,
without touching anything, from my Pocket PC. When i reload the values
into
my Pocket PC application it only says "\n". Now isnt that weird?

Do you, or anybody else, know why this is happening?

It seems like its not saving the "\r"-part of my text???

Thanks so far for your help. Really appreciate it. :)

--


Jimmy
Alex Feinman said:
Add to your code
byte[] bytes = System.Text.Encoding.Unicode.GetBytes(s); // s is your string

and examine the bytes in the debugger. Check if the line breaks are 00
0a or
00 0d 00 0a



Alrternatively you can output the hex string using

MessageBox.Show(BitConverter.ToString(System.Text.Encoding.Unicode.GetBytes(
s)));


--
Alex Feinman
---
Visit http://www.opennetcf.org
It is multiline.

I dont know how to check wether it is "\r\n" or just "\n". Can you
give me
any hints on that?

Thanks so far :)

--


Jimmy
"Alex Feinman [MVP]" <[email protected]> skrev i en
meddelelse
Make sure that the textbox where you put the text retrieved from the web
service is multiline. If this does not help, check that the text received
back still has "\r\n" as line terminators and that they are not
reduced
to
"\n"

--
Alex Feinman
---
Visit http://www.opennetcf.org
Hey

Im writing text in a multiline textbox. Im pressing a button wich
results
in
a call to a web service that saves the data in MS SQL Server as ntext.
At
another point in my application i do a select on this ntext field
and
then
i
want that text to go into the same multiline textbox.

My problem is that when i write out the text it puts out a lot of
squares
in
the text where there should be a new line.
textBox.Text = DS.Tables[0].Rows[0]["ntextfield"].ToString();

But if i instead write out the text in a messagebox everything
looks
just
fine.
MessageBox.Show(textBox.Text);

What am i doing wrong here?

Please help.
 
Sorry, kind of late here and I'm probably not thinking straight, but could
you try changing the web service to accept a byte array instead of a string?
Use Encoding.Unicode for conversion to and from a string

--
Alex Feinman
---
Visit http://www.opennetcf.org
Jimmy said:
Hey

Tried to do the messagebox trick just before calling the webservice. At
that point the text is ok.

Then i tried to do the messagebox trick in my webservice (well, not
exactly a messagebox, but i wrote it to a filestream). When i do that as
the first thing in my webservice, i can see that it has cut of the "\r".
So i guess the problem is in the transfering of the variable to the
webservice.

Now im totally lost.

How do i fix this?

Thanks so far :)

--


Jimmy
Alex Feinman said:
What does your web service look like?

--
Alex Feinman
---
Visit http://www.opennetcf.org
Jimmy said:
Thanks :)

Used the MessageBox.Show instead of the debugger. Found that easier :)

Ok, so now i can see that it actually only writes the "\n".

I can update this field from the web wich i use to input test data. So
everytime i want to start over i just fill in the testdata from there.
After
having done that i start the application on my pocket PC again. When i
load
these values it actually says "\r\n". Then i save the exact same data,
without touching anything, from my Pocket PC. When i reload the values
into
my Pocket PC application it only says "\n". Now isnt that weird?

Do you, or anybody else, know why this is happening?

It seems like its not saving the "\r"-part of my text???

Thanks so far for your help. Really appreciate it. :)

--


Jimmy
"Alex Feinman [MVP]" <[email protected]> skrev i en meddelelse
Add to your code
byte[] bytes = System.Text.Encoding.Unicode.GetBytes(s); // s is your
string

and examine the bytes in the debugger. Check if the line breaks are 00
0a
or
00 0d 00 0a



Alrternatively you can output the hex string using


MessageBox.Show(BitConverter.ToString(System.Text.Encoding.Unicode.GetBytes(
s)));


--
Alex Feinman
---
Visit http://www.opennetcf.org
It is multiline.

I dont know how to check wether it is "\r\n" or just "\n". Can you
give
me
any hints on that?

Thanks so far :)

--


Jimmy
"Alex Feinman [MVP]" <[email protected]> skrev i en
meddelelse
Make sure that the textbox where you put the text retrieved from the
web
service is multiline. If this does not help, check that the text
received
back still has "\r\n" as line terminators and that they are not
reduced
to
"\n"

--
Alex Feinman
---
Visit http://www.opennetcf.org
Hey

Im writing text in a multiline textbox. Im pressing a button wich
results
in
a call to a web service that saves the data in MS SQL Server as
ntext.
At
another point in my application i do a select on this ntext field
and
then
i
want that text to go into the same multiline textbox.

My problem is that when i write out the text it puts out a lot of
squares
in
the text where there should be a new line.
textBox.Text = DS.Tables[0].Rows[0]["ntextfield"].ToString();

But if i instead write out the text in a messagebox everything
looks
just
fine.
MessageBox.Show(textBox.Text);

What am i doing wrong here?

Please help.
 
Hey

Well its kinda early here. I just woke up, so i wouldnt have seen any
messages before i wrote my last message.

Seems like youre thinking pretty straight, because the last thing you told
me here, really did the trick :)

It seems like "\r" is cleared from the string when you sent it to a web
service. To solve that i did just as you suggested.

In the call to my webservice i changed field3 to the following:
System.Text.Encoding.Unicode.GetBytes(field3.Text.Replace(";",":"))

And in my webservice i accepted a:
byte[] field3

When ever i use my field3 variable i use:
System.Text.Encoding.Unicode.GetString(field3);

I get a fine result in both my web application and on the Pocket PC, so it
seems to be the work around for this problem.

Thanks for your help. I really appreciate it :)

If you have any explanation on why it cant send the string to a webservice
without clearing the "\r"s, im very interested in knowing that. Anyway, i
can move on with my project now, thanks to you.

Thanks :)


--


Jimmy

Alex Feinman said:
Sorry, kind of late here and I'm probably not thinking straight, but could
you try changing the web service to accept a byte array instead of a
string?
Use Encoding.Unicode for conversion to and from a string

--
Alex Feinman
---
Visit http://www.opennetcf.org
Jimmy said:
Hey

Tried to do the messagebox trick just before calling the webservice. At
that point the text is ok.

Then i tried to do the messagebox trick in my webservice (well, not
exactly a messagebox, but i wrote it to a filestream). When i do that as
the first thing in my webservice, i can see that it has cut of the "\r".
So i guess the problem is in the transfering of the variable to the
webservice.

Now im totally lost.

How do i fix this?

Thanks so far :)

--


Jimmy
Alex Feinman said:
What does your web service look like?

--
Alex Feinman
---
Visit http://www.opennetcf.org
Thanks :)

Used the MessageBox.Show instead of the debugger. Found that easier :)

Ok, so now i can see that it actually only writes the "\n".

I can update this field from the web wich i use to input test data. So
everytime i want to start over i just fill in the testdata from there.
After
having done that i start the application on my pocket PC again. When i
load
these values it actually says "\r\n". Then i save the exact same data,
without touching anything, from my Pocket PC. When i reload the values
into
my Pocket PC application it only says "\n". Now isnt that weird?

Do you, or anybody else, know why this is happening?

It seems like its not saving the "\r"-part of my text???

Thanks so far for your help. Really appreciate it. :)

--


Jimmy
"Alex Feinman [MVP]" <[email protected]> skrev i en
meddelelse
Add to your code
byte[] bytes = System.Text.Encoding.Unicode.GetBytes(s); // s is your
string

and examine the bytes in the debugger. Check if the line breaks are 00
0a
or
00 0d 00 0a



Alrternatively you can output the hex string using


MessageBox.Show(BitConverter.ToString(System.Text.Encoding.Unicode.GetBytes(
s)));


--
Alex Feinman
---
Visit http://www.opennetcf.org
It is multiline.

I dont know how to check wether it is "\r\n" or just "\n". Can you
give
me
any hints on that?

Thanks so far :)

--


Jimmy
"Alex Feinman [MVP]" <[email protected]> skrev i en
meddelelse
Make sure that the textbox where you put the text retrieved from
the
web
service is multiline. If this does not help, check that the text
received
back still has "\r\n" as line terminators and that they are not
reduced
to
"\n"

--
Alex Feinman
---
Visit http://www.opennetcf.org
Hey

Im writing text in a multiline textbox. Im pressing a button wich
results
in
a call to a web service that saves the data in MS SQL Server as
ntext.
At
another point in my application i do a select on this ntext field
and
then
i
want that text to go into the same multiline textbox.

My problem is that when i write out the text it puts out a lot of
squares
in
the text where there should be a new line.
textBox.Text = DS.Tables[0].Rows[0]["ntextfield"].ToString();

But if i instead write out the text in a messagebox everything
looks
just
fine.
MessageBox.Show(textBox.Text);

What am i doing wrong here?

Please help.
 
Ok, there is actually a better solution. By default, an autogenerated proxy
uses SoapHttpClientProtocol as a base class. What happens underneath is that
your parameters are passed inside a POST request as an XML document. By
default XML document does not preserve whitespace and you cannot affect this
(at least I was not able to find a way to do this).

An alternative is to build a proxy yourself using wsdl.exe (in the .NET
SDK - \Program Files\Microsoft Visual Studi .NET 2003\sdk\v1.1\bin) and
specify a different protocol.

wsdl http://myserver/myservice/service.asmx /Protocol:HttpGet

Now you can import the resulting file into your project and use it instead
of the web reference.

One catch remains. For some reason I was not able to use wsdl with
/Protocol:HttpPost. Why would I want to do that? Because the standard
configuration of ASP.NET 1.1. disallows GET on web services. You can change
that in the machine.config or you can use POST. How? By opening a generated
proxy and changing the base class from HttpGetClientProtocol to
HttpPostClientProtocol and UrlParameterWriter to HtmlFormParameterWriter

This way you won't have to convert your strings to and from byte arrays

I really need to blog this, but I forgot my blog account

--
Alex Feinman
---
Visit http://www.opennetcf.org
Jimmy said:
Hey

Well its kinda early here. I just woke up, so i wouldnt have seen any
messages before i wrote my last message.

Seems like youre thinking pretty straight, because the last thing you told
me here, really did the trick :)

It seems like "\r" is cleared from the string when you sent it to a web
service. To solve that i did just as you suggested.

In the call to my webservice i changed field3 to the following:
System.Text.Encoding.Unicode.GetBytes(field3.Text.Replace(";",":"))

And in my webservice i accepted a:
byte[] field3

When ever i use my field3 variable i use:
System.Text.Encoding.Unicode.GetString(field3);

I get a fine result in both my web application and on the Pocket PC, so it
seems to be the work around for this problem.

Thanks for your help. I really appreciate it :)

If you have any explanation on why it cant send the string to a webservice
without clearing the "\r"s, im very interested in knowing that. Anyway, i
can move on with my project now, thanks to you.

Thanks :)


--


Jimmy

Alex Feinman said:
Sorry, kind of late here and I'm probably not thinking straight, but
could you try changing the web service to accept a byte array instead of
a string?
Use Encoding.Unicode for conversion to and from a string

--
Alex Feinman
---
Visit http://www.opennetcf.org
Jimmy said:
Hey

Tried to do the messagebox trick just before calling the webservice. At
that point the text is ok.

Then i tried to do the messagebox trick in my webservice (well, not
exactly a messagebox, but i wrote it to a filestream). When i do that as
the first thing in my webservice, i can see that it has cut of the "\r".
So i guess the problem is in the transfering of the variable to the
webservice.

Now im totally lost.

How do i fix this?

Thanks so far :)

--


Jimmy
"Alex Feinman [MVP]" <[email protected]> skrev i en meddelelse
What does your web service look like?

--
Alex Feinman
---
Visit http://www.opennetcf.org
Thanks :)

Used the MessageBox.Show instead of the debugger. Found that easier :)

Ok, so now i can see that it actually only writes the "\n".

I can update this field from the web wich i use to input test data. So
everytime i want to start over i just fill in the testdata from there.
After
having done that i start the application on my pocket PC again. When i
load
these values it actually says "\r\n". Then i save the exact same data,
without touching anything, from my Pocket PC. When i reload the values
into
my Pocket PC application it only says "\n". Now isnt that weird?

Do you, or anybody else, know why this is happening?

It seems like its not saving the "\r"-part of my text???

Thanks so far for your help. Really appreciate it. :)

--


Jimmy
"Alex Feinman [MVP]" <[email protected]> skrev i en
meddelelse
Add to your code
byte[] bytes = System.Text.Encoding.Unicode.GetBytes(s); // s is your
string

and examine the bytes in the debugger. Check if the line breaks are
00 0a
or
00 0d 00 0a



Alrternatively you can output the hex string using


MessageBox.Show(BitConverter.ToString(System.Text.Encoding.Unicode.GetBytes(
s)));


--
Alex Feinman
---
Visit http://www.opennetcf.org
It is multiline.

I dont know how to check wether it is "\r\n" or just "\n". Can you
give
me
any hints on that?

Thanks so far :)

--


Jimmy
"Alex Feinman [MVP]" <[email protected]> skrev i en
meddelelse
Make sure that the textbox where you put the text retrieved from
the
web
service is multiline. If this does not help, check that the text
received
back still has "\r\n" as line terminators and that they are not
reduced
to
"\n"

--
Alex Feinman
---
Visit http://www.opennetcf.org
Hey

Im writing text in a multiline textbox. Im pressing a button
wich
results
in
a call to a web service that saves the data in MS SQL Server as
ntext.
At
another point in my application i do a select on this ntext
field and
then
i
want that text to go into the same multiline textbox.

My problem is that when i write out the text it puts out a lot
of
squares
in
the text where there should be a new line.
textBox.Text = DS.Tables[0].Rows[0]["ntextfield"].ToString();

But if i instead write out the text in a messagebox everything
looks
just
fine.
MessageBox.Show(textBox.Text);

What am i doing wrong here?

Please help.
 
hehe... Can see the problem with blogging it ;)

Let me know the address to your blog, if its public.

Thanks for the explanation, and the even cooler solution you provided in
your last reply.

Man, youre cool... ;)

--


Jimmy

Alex Feinman said:
Ok, there is actually a better solution. By default, an autogenerated
proxy uses SoapHttpClientProtocol as a base class. What happens underneath
is that your parameters are passed inside a POST request as an XML
document. By default XML document does not preserve whitespace and you
cannot affect this (at least I was not able to find a way to do this).

An alternative is to build a proxy yourself using wsdl.exe (in the .NET
SDK - \Program Files\Microsoft Visual Studi .NET 2003\sdk\v1.1\bin) and
specify a different protocol.

wsdl http://myserver/myservice/service.asmx /Protocol:HttpGet

Now you can import the resulting file into your project and use it instead
of the web reference.

One catch remains. For some reason I was not able to use wsdl with
/Protocol:HttpPost. Why would I want to do that? Because the standard
configuration of ASP.NET 1.1. disallows GET on web services. You can
change that in the machine.config or you can use POST. How? By opening a
generated proxy and changing the base class from HttpGetClientProtocol to
HttpPostClientProtocol and UrlParameterWriter to HtmlFormParameterWriter

This way you won't have to convert your strings to and from byte arrays

I really need to blog this, but I forgot my blog account

--
Alex Feinman
---
Visit http://www.opennetcf.org
Jimmy said:
Hey

Well its kinda early here. I just woke up, so i wouldnt have seen any
messages before i wrote my last message.

Seems like youre thinking pretty straight, because the last thing you
told me here, really did the trick :)

It seems like "\r" is cleared from the string when you sent it to a web
service. To solve that i did just as you suggested.

In the call to my webservice i changed field3 to the following:
System.Text.Encoding.Unicode.GetBytes(field3.Text.Replace(";",":"))

And in my webservice i accepted a:
byte[] field3

When ever i use my field3 variable i use:
System.Text.Encoding.Unicode.GetString(field3);

I get a fine result in both my web application and on the Pocket PC, so
it seems to be the work around for this problem.

Thanks for your help. I really appreciate it :)

If you have any explanation on why it cant send the string to a
webservice without clearing the "\r"s, im very interested in knowing
that. Anyway, i can move on with my project now, thanks to you.

Thanks :)


--


Jimmy

Alex Feinman said:
Sorry, kind of late here and I'm probably not thinking straight, but
could you try changing the web service to accept a byte array instead of
a string?
Use Encoding.Unicode for conversion to and from a string

--
Alex Feinman
---
Visit http://www.opennetcf.org
Hey

Tried to do the messagebox trick just before calling the webservice. At
that point the text is ok.

Then i tried to do the messagebox trick in my webservice (well, not
exactly a messagebox, but i wrote it to a filestream). When i do that
as the first thing in my webservice, i can see that it has cut of the
"\r". So i guess the problem is in the transfering of the variable to
the webservice.

Now im totally lost.

How do i fix this?

Thanks so far :)

--


Jimmy
"Alex Feinman [MVP]" <[email protected]> skrev i en
meddelelse What does your web service look like?

--
Alex Feinman
---
Visit http://www.opennetcf.org
Thanks :)

Used the MessageBox.Show instead of the debugger. Found that easier
:)

Ok, so now i can see that it actually only writes the "\n".

I can update this field from the web wich i use to input test data.
So
everytime i want to start over i just fill in the testdata from
there. After
having done that i start the application on my pocket PC again. When
i load
these values it actually says "\r\n". Then i save the exact same
data,
without touching anything, from my Pocket PC. When i reload the
values into
my Pocket PC application it only says "\n". Now isnt that weird?

Do you, or anybody else, know why this is happening?

It seems like its not saving the "\r"-part of my text???

Thanks so far for your help. Really appreciate it. :)

--


Jimmy
"Alex Feinman [MVP]" <[email protected]> skrev i en
meddelelse
Add to your code
byte[] bytes = System.Text.Encoding.Unicode.GetBytes(s); // s is
your
string

and examine the bytes in the debugger. Check if the line breaks are
00 0a
or
00 0d 00 0a



Alrternatively you can output the hex string using


MessageBox.Show(BitConverter.ToString(System.Text.Encoding.Unicode.GetBytes(
s)));


--
Alex Feinman
---
Visit http://www.opennetcf.org
It is multiline.

I dont know how to check wether it is "\r\n" or just "\n". Can you
give
me
any hints on that?

Thanks so far :)

--


Jimmy
"Alex Feinman [MVP]" <[email protected]> skrev i en
meddelelse
Make sure that the textbox where you put the text retrieved from
the
web
service is multiline. If this does not help, check that the text
received
back still has "\r\n" as line terminators and that they are not
reduced
to
"\n"

--
Alex Feinman
---
Visit http://www.opennetcf.org
Hey

Im writing text in a multiline textbox. Im pressing a button
wich
results
in
a call to a web service that saves the data in MS SQL Server as
ntext.
At
another point in my application i do a select on this ntext
field and
then
i
want that text to go into the same multiline textbox.

My problem is that when i write out the text it puts out a lot
of
squares
in
the text where there should be a new line.
textBox.Text = DS.Tables[0].Rows[0]["ntextfield"].ToString();

But if i instead write out the text in a messagebox everything
looks
just
fine.
MessageBox.Show(textBox.Text);

What am i doing wrong here?

Please help.
 
Back
Top