Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

WCF Upload Large Files Report progress vis UIProgressView

$
0
0

I have create a WCF Service that allows uploading large files via BasicHttpBinding using streaming and it is working great! I would like to extended this to show a progress bar (UIProgressView) so that when a large file is being uploaded in 65k chunks, the user can see that it is actively working.

The client code calling the WCF Service is:

BasicHttpBinding binding = CreateBasicHttp ();
BTSMobileWcfClient _client = new BTSMobileWcfClient (binding, endPoint);
_client.UploadFileCompleted += ClientUploadFileCompleted;
byte[] b = File.ReadAllBytes (zipFileName);
using (new OperationContextScope(_client.InnerChannel)) {
   OperationContext.Current.OutgoingMessageHeaders.Add(System.ServiceModel.Channels.MessageHeader.CreateHeader("SalvageId","",iBTSSalvageId.ToString()));
   OperationContext.Current.OutgoingMessageHeaders.Add(System.ServiceModel.Channels.MessageHeader.CreateHeader("FileName","",Path.GetFileName(zipFileName)));
   OperationContext.Current.OutgoingMessageHeaders.Add(System.ServiceModel.Channels.MessageHeader.CreateHeader("Length","",b.LongLength));
   _client.UploadFileAsync(b);
}

On the server side, I read the file stream in 65k chuncks and do report back to the calling routine "bytes read", etc. A snippet of code for that is:

using (FileStream targetStream = new FileStream(filePath, FileMode.CreateNew, FileAccess.Write)) {
  //read from the input stream in 65000 byte chunks
  const int chunkSize = 65536;
  byte[] buffer = new byte[chunkSize];
  do {
    // read bytes from input stream
    int bytesRead = request.FileData.Read(buffer, 0, chunkSize);
    if (bytesRead == 0) break;
    // write bytes to output stream
    targetStream.Write(buffer, 0, bytesRead);
  } while (true);
  targetStream.Close();
}

But I don't know how to hook into the callback on the Xamarin side to receive the "bytes read" versus "total bytes to send" so I can update the UIProgressView.

Has anyone tried this or is this even possible?

Thanks In Advance,

Bo


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>