tags:

views:

82

answers:

2

I'm writing a WCF service which will be used to receive big files (mp3 files and others), process them and then return an mp3 audio file. I don't want to save those files in the filesystem, I'd just like to process them, and then return an audio file. the problem is I'd like the process to use as low memory as possible.

how would I accomplish this ?

I wrote this :

[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;
  }
}
+5  A: 

Have a look at WCF message streaming - you basically create one parameter as type "Stream" - and optionally the return value as "Stream" as well - and then you don't have to buffer the whole multi-megabyte file, but you'll be transferring the file in streaming chunks.

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

MSDN docs are here: http://msdn.microsoft.com/en-us/library/ms731913.aspx

Marc

marc_s
A: 

The way to do this is to use streaming, see:

http://msdn.microsoft.com/en-us/library/ms731913.aspx

Shiraz Bhaiji