由于silverlight中的System.Text.Encoding 没有Default属性,在汉字转换出现乱码。

处理方式:

1.把txt另存为UTF8或unicode格式。

2.把文本文件传入,后台转换数据。

       void button1_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();
            open.ShowDialog();
            service1.HelloWorldAsync(MainPage.StreamToByte(open.File.OpenRead()));
        }

        public static byte[] StreamToByte(Stream Reader)
        {
            try
            {
                MemoryStream mem = new MemoryStream(1024 * 500);
                byte[] buffer = new byte[1024];
                int bytesRead = 0;
                int TotalByteRead = 0;

                while (true)
                {
                    bytesRead = Reader.Read(buffer, 0, buffer.Length);
                    if (bytesRead == 0)
                        break;
                    TotalByteRead += bytesRead;
                    mem.Write(buffer, 0, buffer.Length);
                }

                if (mem.Length > 0)
                {
                    return mem.ToArray();
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ep)
            {
                throw ep;
            }
        }