你只能用Stream,MemoryStream.替换.
FileStream不支持序列化.
你的问题我以前也和别人讨论过。WCF分布式开发步步为赢(11):WCF流处理(Streaming)机制 。后面回复讨论里有。
你可以自己定义一个数据契约,包含一个filename,一个byte[] dada.属性。也可以传递数据。也可以直接返回byte[] 数组。参考测试代码:
//Pass user with pic data
public byte[] GetBytes(string fileName)
{
//String fileName = "WaterLily.jpg";
String filePath = AppDomain.CurrentDomain.BaseDirectory + fileName;
if (File.Exists(filePath))
{
//Read file.
byte[] bFile = File.ReadAllBytes(filePath);
// codes here to deal with the stream Stream stream =
Console.WriteLine("Output data length is {0},at {1}", bFile.Length, DateTime.Now.ToLongTimeString());
return bFile;
}
else
{
Console.WriteLine("No file was found with name {0},at {1}", fileName, DateTime.Now.ToLongTimeString());
return null;
}
}
用MemoryStream替换就好了。