1

My iOS application allows a user to store files such as PDF's, Images, etc. We need to synchronize the app files to the cloud as we also offer the user a web portal to view the same data. I use WCF (Mtom encoding/streaming) in my Windows Forms app but this is not working in Xamarion.iOS (MonoTouch). There seems to be a problem with Mtom message encoding so I'm looking at an alternate and/or better way of getting files uploaded reliably such as streaming, showing progress, and using async await in C# 5 if possible.

What method do you recommend and if you have any sample code or links this would be great. Also, what is required in IIS 7.5 as I run Windows Server 2008 R2. Lastly, any firewall issues as I run a Watchguard appliance so if I need to open anything to allow this to work please advise. I assume though this would occur over HTTP or HTTPS.

I've done some research on web client, webDAV, etc, but not sure what is really the best approach for this scenario.

Thank you.

Neal
  • 9,487
  • 15
  • 58
  • 101

2 Answers2

2

HttpClient (async) or WebClient will handle uploads just fine. You can create an ASP.NET upload handler or MVC action to read a HTTP posted file.

Some helpful links:

C# HttpClient 4.5 multipart/form-data upload

Getting the upload progress during file upload using Webclient.Uploadfile

http://haacked.com/archive/2010/07/16/uploading-files-with-aspnetmvc.aspx

Edit: See Larry OBrien's answer explaining the iOS 7 native MonoTouch.Foundation.NSUrlSession which allows background transfers.

Community
  • 1
  • 1
kwcto
  • 3,494
  • 2
  • 26
  • 33
  • bayfrontconsulting thank you! Any opinion as to what's better for uploading - WCF with Mtom/streaming vs. webclient? – Neal Sep 16 '13 at 15:47
  • Honestly, I'd stay away from the more heavyweight stuff like WCF in the mobile space. I'm sure many people have used it successfully though. – kwcto Sep 17 '13 at 02:10
2

iOS 7 introduces a new class, MonoTouch.Foundation.NSUrlSession, which is the preferred way to transfer larger files to and from the Web. NSUrlSession transfers can work when the application is in the background.

The programming model is explained in this article.

Here is a sample application that demonstrates the technique.

Larry OBrien
  • 8,484
  • 1
  • 41
  • 75
  • Thank you - certainly interesting option for iOS 7 and above. Need an upload option (not download) and the system from device to IIS config to implement this option. – Neal Sep 19 '13 at 13:36
  • @Neal `NSUrlSession` handles uploads as well, but I don't know the server-side aspect of the answer. – Larry OBrien Sep 19 '13 at 16:32