2

I'm about to implement a FileService using WCF. It should be able to upload files by providing the filecontent itself and the filename. The current ServiceContract looks like the following

[ServiceContract]
public interface IFileService
{
    [OperationContract]
    [FaultContract(typeof(FaultException))]
    byte[] LoadFile(string relativeFileNamePath);

    [OperationContract]
    [FaultContract(typeof(FaultException))]
    void SaveFile(byte[] content, string relativeFileNamePath);
}

It works fine at the moment, but i want to be able to reduce the network payload of my application using this Fileservice. I need to provide many files as soon as the user openes a specific section of my application, but i might be able to cancel some of them as soon as the user navigates further through the application. As many of mine files are somewhere between 50 and 300 MB, it takes quite a few seconds to transfer the files (the application might run on very slow networks, it might take up a minute).

To clarify and to outline the difference to all those other WCF questions: The specific problem is that providing the data between client <-> server is the bottleneck, not the performance of the service itself. Is changing the interface to a streamed WCF service reasonable?

Community
  • 1
  • 1
ElGaucho
  • 408
  • 2
  • 14

1 Answers1

0

It is a good practice to use a stream if the file size is above a certain amount. At my work on the enterprise application we are writing, if it is bigger than 16kb then we stream it. If it is less than that, we buffer. Our file service is specially designed to handle this logic.

When you have the transfer mode of your service set to buffer, it will buffer on the client as well as on the service when you are transmitting your data. This means if you are sending a 300mb file, it will buffer all 300mb during the call on both ends before the call is complete. This will definitely create bottlenecks. For performance reasons, this should only be when you have small files that buffer quickly. Otherwise, a stream is the best way to go.

If the majority or all of your files are larger files I'd switch to using a stream.

David Gunderson
  • 671
  • 14
  • 20