Attilah
Attilah

Reputation: 17932

WCF sending big files

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;
  }
}

Upvotes: 1

Views: 1488

Answers (2)

marc_s
marc_s

Reputation: 755531

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

Upvotes: 6

Shiraz Bhaiji
Shiraz Bhaiji

Reputation: 65491

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

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

Upvotes: 1

Related Questions