WCF发送大文件

Att*_*lah 1 .net c# wcf

我正在编写一个WCF服务,用于接收大文件(mp3文件和其他文件),处理它们然后返回一个mp3音频文件.我不想将这些文件保存在文件系统中,我只想处理它们,然后返回一个音频文件.问题是我希望使用尽可能低内存的进程.

我怎么做到这一点?

我写了这个:

[ServiceContract]
public interface IService
{
    [FaultContract(typeof(ConversionFault))]
    [OperationContract]
    byte[] ProcessAudio(byte[] audio,string filename);
}

public class MyService : IService
{
  public byte[] ProcessAudio(byte[] audio,string filename)
  {
        //...
        //do the processing here.

        //return the converted audio.
        return processedAudio;
  }
}
Run Code Online (Sandbox Code Playgroud)

mar*_*c_s 6

看看WCF 消息流 - 你基本上创建一个参数作为类型"流" - 并且可选地返回值作为"流" - 然后你不必缓冲整个多兆字节文件,但你'将以流媒体块的形式传输文件.

[ServiceContract]
public interface IService
{
    [FaultContract(typeof(ConversionFault))]
    [OperationContract]
    Stream ProcessAudio(Stream audio, string filename);
}
Run Code Online (Sandbox Code Playgroud)

MSDN文档在这里:http://msdn.microsoft.com/en-us/library/ms731913.aspx