Click to See Complete Forum and Search --> : Single byte return encoding from Web Service


plaingray
May 25th, 2007, 06:03 AM
Hello, I have a problem with what I believe is the return encoding in a web service made in VB.NET. In reality it's one of our customers' application that is broken but I'm able to reproduce it but not solve it.

Below is a snippet of code from a simple function made in VB.NET

Public Function HandleMsg() As String
...
Dim b() As Byte = {255, 128, 234, 244}
Dim s As String = System.Text.Encoding.Default.GetString(b)
'Debug.WriteLine(s)
'Debug.WriteLine(System.Text.Encoding.Default.GetByteCount(s))
Return System.Text.Encoding.Default.GetByteCount(s)

Result:
String = ÿ€êô
Byte count = 4

Instead of using Debug.WriteLine I simply returned the String and the Byte Count in two tests and it replied exactly what it says above, four freaky chars and a byte count of 4.

However, when I look at that packages sent with a network sniffer, even though the byte count says 4, the string in the message contains 8! bytes. I dont want 8 bytes, I want 4. I've tried all kinds of suggestions found everywhere but nothing I change will make the function return the 4 bytes.

Following test case with the same function:

Return Chr(228)


which definitely should return one byte also returns two bytes in a network sniffer. I've tried everything available at msdn and a lot of other places without success. I've tried setting responseEncoding in globalization and lots of encoding settings in the code but to no avail.
What I would like is the function to return single byte strings in ISO-8959-1 encoding if possible, but really, Return Chr(228) should be one byte in a sniffer.

Is there anyone out there with any helpful hints?