Best way to upload files from iOS app to Windows Server? - c#

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.

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.

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.

Related

How to develop Smart Client Application

Hi.
I have several questions. I developed an application using Visual Studio 2010. The application is developed using Windows Form and the program was wrote using C#.
This application needs to be run on a server. There are several clients connected to the server that will access and use that application through the browser. I know this can be done using Smart Client technique. But I don't really understand how to do it. My questions are:
Is there any syntax/class/methods/function that I need to include in my application? How to use it?
What settings/configuration do I need to set up so that the client computer can access the application in the server through their browser?
I know this can be done using ClickOnce but I don't know how. Can anybody tell me or show me the steps that I need to do to implement this?
Is there any syntax/class/methods/function that I need to include in my application? How to use it?
There are a few - but this is a large area. I would point you at couple:
WCF
ASP.NET Web API.
I would advise to use the later as it appears to be where the modern development is heading (at least to me).
Put simply, you will write your own web server, host it either in your WinForms application or migrate your WinForms to be a web application and host it on IIS, for example. Your web server will expose some API, which will likely to be based on HTTP protocol. A client application will hit web URLs. This will be a request-response paradigm.
Because this is a large area, I cannot name you exact classes, but have a look at ASP.NET site for samples.
What settings/configuration do I need to set up so that the client computer can access the application in the server through their browser?
It depends on the technology. Usually it's pretty simple - get it from tutorials and samples. In most cases this will be *.config file XML code and some minor bootstrapping in .cs files.
I know this can be done using ClickOnce but I don't know how. Can anybody tell me or show me the steps that I need to do to implement this?
ClickOnce is a deployment tool. You probably don't need that at this point.

How can I implement a C# server that receives JSON data and how to POST it?

I have a phonegap iOS app which has a form that, when submitted, it should post some json data to a server and get a response. I have to use C# on the server side and listen somehow when the json is posted from the form in the phonegap app, do some stuff with the data and then respond to the phonegap app. How can I implement the c# server and how should I post the data from my html form? I am experienced in c# desktop applications, but I am really new to everything related to web stuff. The ios app is running in an iphone simulator on a mac in my local network. I have searched for resources but I haven't been able to do this and have been trying for a while. I think I don't need the whole code, just advice on how to do it and what to use.
Any help will be greatly appreciated.
Thanks.
ASP.NET Web Api is exactly what you need. It's a framework for creating web APIs that receive and respond to requests coming through the web, which of course includes JSON data.
ASP.Net MVC and/or ASP.Net WebAPI are perfect for this. Check out the resources at http://asp.net.
The MS Web API won't help with writing a server.
You don't need to write your own server, but you can if you so choose.
Setup and run IIS.
Make a simple ASP.NET Web Forms application
Handle the Page_Load event
Read the value of your json from the posted data using Request.Form["json"]; or whatever you called your posted fields.
System.Web.Script.Serialization.JavaScriptSerializer will help to deserialize your json. Just make a class for your types. You'll have add a reference to System.Web.Extensions.
Publish your application to IIS.
I can highly recommend ServiceStack. It's highly testable, easy to host, and in my experience magnitudes faster than any of the MS web service platforms. Plus, as you don't state what platform your server is, ServiceStack can be hosted on both Windows and Linux systems.
https://github.com/ServiceStack/ServiceStack/wiki/Mono
https://github.com/ServiceStack/ServiceStack/wiki/Self-hosting

How to create and save a text file with JavaScript

Do you know any cross-browser method to create and save a file with JavaScript on the client-side?
Considerations:
I can't save it on the server because the file is going to be read from a fiscal printer.
The server can't access the client. This is obvious because we are talking about a web application in the web, so the server can't access a client folder.
New ActiveXObject("Scripting.FileSystemObject"); is ONLY for Internet Explorer and even then not for all versions.
We are talking about printing on a fiscal printer, so I can't ask the cashier in the supermarket to download the text file and save it in a folder where the fiscal printer can read it.
If not JavaScript, what else can I use in my ASP, .Net 4.0, C# web application?
Basically, you said it, "we are talking about a web application." Do you know any web applications that save a file to your hard drive (besides cookies) without showing you a download prompt first?
Having said that, browsers have started to offer a persistence API that goes beyond cookies. (See, for example, this article.) But such a solution wouldn't meet your requirement of being cross-browser.
Your only options are to use persistance APIs from HTML5 or to create a browser plugin (activex control on IE, NPAPI plugin on others) that can do the file access for you. You could use FireBreath to do this, and it would be relatively simple if you know C++.
That said, it is a really dangerous idea; it is difficult to prevent people from using your plugin in other pages, so your plugin has to somehow be smart enough to keep itself from being abused by malicious sites that want to read (or even write) arbitrary data to your hard drive.
There is, after all, a reason why browsers don't natively support this. I'd look at HTML5.
you can do that by Client side Web services just make a function in web service to create a text file in your hard drive then convert the web service in to the client side service when u do that .Net framework make a client side java script then u will be able to call the server side function using Java script in client side after that your file will not be posted in the server it will remain save in your hard drive ok
we came out with a simple windows service nodejs app to be installed in the local machine.
When the web application need to create a file it just sends an API call to this app using localhost and that will write the file for it.
Cheers.

What .Net tools should I consider using to build an application to provide monitoring of our real time systems?

I want to build some sort of interface that will monitor our real time routing/switching system. I would like to give a lot of visual feedback to be able to monitor its status visually. Our system and clients are not co-located so they would need to connect via TCP/IP.
I would like to be able to service any number of monitoring clients (although this will probably only ever be about 4-6 clients). I thought of using SilverLight but there appears to be one or two tricks involved in getting SilverLight to connect back to an application running on a different port.
I have also thought of using HTML5 canvas and websockets. Another alternative is to just create the clients using normal Window Forms and perhaps WPF. But this means that to monitor the application the client will have to be downloaded before. I would prefer something that is as easily accessible as web app?
What are some of the more common application stacks to achieve this? What should I watch out for?
EDIT:
Just to add: This will be an internal tool only. But we have offices in a couple of locations.
any choice in this direction could be subjective and arguable, surely somebody could suggest any possible web framework or language...
I would consider, however because of your .NET and C# tags, ASP.NET MVC 3, so basically web based plugin-less ( NO Silverlight ) HTML 5 solution.
Consider that StackOverflow is done in same way (MVC, ASP.NET, SQL Server... ) and outperforms as we all know.
the way you grab the underlying events from TCP, so the way you capture and provide the data from TCP, it's another thing from the front end, I would probably write a Windows Service if the traffic is so high and you want to grab and store data anything regardless any active client connection.
There are plenty of real time charting controls out there also for MVC, MS Chart Control. DevExpress, ExtJS integrated ones...
"real time" and Browser is bothering me.
I would indeed go WPF or WinForms. Using the ClickOnce-Deployment you can make this a no-pain for the user and you can roll-out new versions just by redeploying them and having the user restart the application.
In my company this works really fine and we have no problems whatsoever. The only problem with this is, that the app.config is somewhat hard to find and keep current/valid (redeploy) but in your case this won't change per client (or so I guess).
I agree with #Davide - I would go for a WebService that will obtain all routing/switching data in realtime. You will have a web application and on the client side you will have JQuery/AJAX fetching realtime data from the WebService component.
I've seen cool demo's of Web Orb doing something similar to what you want. http://www.themidnightcoders.com/
If you are starting from scratch, it would be good to check out WCF (Windows Communication Foundation). It's great because it can expose your functionality in many ways, using nothing more than modifying a config file.
If you want a Windows client app, you can host it in a Windows Service, or simply include it as a side assembly. For web apps, you can choose between various formats (JSON, XML), channels (HTTP, TCP) and protocols (SOAP, ODP).
If I got it right, there will be a server-side application which will collect information from the devices and expose it to clients as a service. In that case, a WCF application might be hosted in a Windows Service or IIS on a server machine, and expose the data though one or more endpoints (HTTP, TCP).
I am not aware of problems in connecting a SilverLight app to a service, but I would rather go for a HTML5/JavaScript combo instead, for easier deploying and compatibility with a wider range of devices (no plugins needed). ASP.NET MVC should be the best choice for the web app.

WP7 Image Upload

I'm trying to create a WP7 application that will upload an image to my website. I tried using FTP but microsoft have removed that feature from WP7. Apparently the only other way at the moment is to call a webservice running on my website that will do the ftp upload for me.
Simple enough, i turn the image into a byte array and make a web request to my website.
But i'm not sure on the code on either side, client or server. I'm using asp but i'm not having much look, i've got as far as turning the image into a byte array but i dont know how i go about sending this data. All the info i've found is for web apps or windows forms not WP7.
Thanks,
James
Hey Cadab have you checked out this link yet? It looks like the code for the application on the client as well as server side. I have not tried this myself but I'm pretty sure it would work.
You should take a look at this question because it has code and seems pretty close to what your trying to accomplish.
You might also want to check out this question.
Although these were written in standard silverlight (browser or client) they should work for WP7 with minor modifications.
Let me know if this helps.

Categories