Problem with WCF Streaming
        Posted  
        
            by H4mm3rHead
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by H4mm3rHead
        
        
        
        Published on 2010-03-17T20:21:06Z
        Indexed on 
            2010/03/17
            20:31 UTC
        
        
        Read the original article
        Hit count: 606
        
Hi, I was looking at this thread: http://stackoverflow.com/questions/1935040/how-to-handle-large-file-uploads-via-wcf
I need to have a web service hosted at my provider where i need to upload and download files to. We are talking videos from 1Mb to 100Mb hence the streaming approach.
I cant get it to work, i declared an Interface:
[ServiceContract]
    public interface IFileTransferService
    {
        [OperationContract]
        void UploadFile(Stream stream);
    }
and all is fine, i implement it like this:
 public string FileName = "test";
        public void UploadFile(Stream stream)
        {
            try
            {
                FileStream outStream = File.Open(FileName, FileMode.Create, FileAccess.Write);
                const int bufferLength = 4096;
                byte[] buffer = new byte[bufferLength];
                int count = 0;
                while((count = stream.Read(buffer, 0, bufferLength)) > 0)
                {
                    //progress
                    outStream.Write(buffer, 0, count);
                }
                outStream.Close();
                stream.Close();
                //saved
            }
            catch(Exception ex)
            {
                throw new Exception("error: "+ex.Message);
            }
        }
Still no problem, its published to my webserver out on the interweb. So far so good.
Now i make a reference to it and will pass it a FileStream, but the argument is now a byte[] - why is that and how do i get it the proper way for streaming?
Edit My binding look like this:
 <bindings>
      <basicHttpBinding>
        <binding name="StreamingFileTransferServicesBinding"
                 transferMode="StreamedRequest"
                 maxBufferSize="65536"
                 maxReceivedMessageSize="204003200"  />
      </basicHttpBinding>
    </bindings>
I can consume it without problems, and get no errors - other than my input parameter has changed from a stream to a byte[]
© Stack Overflow or respective owner