web service的缓冲区溢出????谁能解决?
caomo 2001-11-20 10:42:40 在web service函数中想对二进制文件编码,
[webmethod]
public string GetFile(string filePath)
{FileStream myfile=File.OpenRead(filePath);
BinaryReader br=new BinaryReader(myfile);
byte[] btBuf=new byte[myfile.Length];
long i=0;
while (br.PeekChar()>-1)
{
btBuf[i]=br.ReadByte();
i++;
}
myfile.Close();
return System.Convert.ToBase64String(btBuf);
}
调用时当文件大于4k就出现:
未处理的“System.Web.Services.Protocols.SoapException”类型的异常出现在 syst
em.web.services.dll 中
附加信息:System.Web.Services.Protocols.SoapException: 服务器无法处理请求。
---> System.ArgumentException: 转换缓冲区溢出。
at System.Text.UTF8Encoding.GetChars(Byte[] bytes, Int32 byteIndex, Int32
byteCount, Char[] chars, Int32 charIndex, UTF8Decoder decoder)
at System.Text.UTF8Decoder.GetChars(Byte[] bytes, Int32 byteIndex, Int32
byteCount, Char[] chars, Int32 charIndex)
at System.IO.BinaryReader.InternalReadOneChar()
at System.IO.BinaryReader.Read()
at System.IO.BinaryReader.PeekChar()
at useResData.FileServer.GetFile(String filePath) in e:\ddisk\inetpub\www
root\sei\test\useresdata\fileserver.asmx.cs:line 125