Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System.Byte[] instead of String (SOAP)

Status
Not open for further replies.

Trevahaha

Programmer
Nov 21, 2002
129
US
I have a web service that is connects to a mySQL database, pulls a large text field and returns it to the client.

Example:
Code:
string sql = "SELECT Essay FROM essay WHERE ((EssayID)='1234');";
MySQLCommand cmd = new MySQLCommand(sql, conn);
MySQLDataReader reader = cmd.ExecuteReaderEx();
if(reader.Read()){
  string essay = reader["Essay"].ToString();
  return essay;
}
...

However, when the client receives this, it is receiving "System.Byte[]" instead of the actual string. Why is this? How can I convert this properly. It seems to work fine internally when I populate Lucene.net with the strings (i.e. it's receiving the correct string).

THANKS!!!
 
It is not clear if the above code is on the client side or on the web service method. But, if you receive a huge array, use the StringBuilder to get the string:
Code:
StringBuilder sb = new StringBuilder();
System.Byte[] bytes = {};
foreach (byte b in bytes)
{
   sb.Append(Convert.ToChar(b));
}
string s1 = sb.ToString();
-obislavu-
 
Well.. that was server side. But it says:
Cannot implicitly convert type 'string' to 'byte[]'

I'm just confused why I can't get this string to work...

Here's the entire method (on the server):
Code:
public string getFirstString(string q)
{
  string t="";
  try
  {
  MySQLConnection conn = new MySQLConnection(new MySQLConnectionString("localhost","essay","username","password").AsString);
  conn.Open();
  string sql = "SELECT Essay FROM essay WHERE ((EssayID)='" + q +"');";
  MySQLCommand cmd = new MySQLCommand(sql, conn);
  MySQLDataReader reader = cmd.ExecuteReaderEx();

  if(reader.Read())
  {
   string essay = reader["Essay"].ToString();
   t += essay + ": (length: " + essay.Length + ")<br>";
  }else{
   t = "Essay Not Found";
  }
  reader.Close();
  conn.Close();
}catch(Exception e){
 t += "An Error! " + e.ToString();
}
  return t;
}
}

The client is pretty simple.. it's like:
string variable = servicename.getFirstString("####");
 
Sorry.. I read up on StringBuilder... weird enough.. I still got System.Byte[] returned to the client.

I can send back other strings just fine.. it sends back
Code:
System.Byte[]: (length: 13)

I'm just clueless. hmm.
 
It is strange but I would modify the above code like here:
if (reader.HasRows)
{
while (reader.Read())
{
//...
}
}
else
{
// not found
}
-obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top