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

manrysj
  • 75
  • 1
  • 6
  • is your client generated by SLSvcUtil? Have you scanned it to see if monitors for any sort of progress event? – Jason Feb 25 '14 at 19:39
  • I did use SLSvcUtil to generate the proxy class. I don't see where it reports any progress events. I have a bunch of IAsync and IAsyncResults stuff going on. I tried to follow an example from http://www.codeproject.com/Articles/20364/Progress-Indication-while-Uploading-Downloading-Fi but I don't stream the data the way the example does. – manrysj Feb 25 '14 at 20:44
  • The proxy class could be extended I guess. I would like to keep using the SLSvcUtil so that when future changes are made, I can simply run the utility to update the class. – manrysj Feb 25 '14 at 20:45

0 Answers0