Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ASP.NET Web API as image service

I have an application running on both web and mobile platforms and its users can upload photos using the app. I need a web service to handle uploading and displaying images on both web and mobile applications.

Is it a good idea to use ASP.NET Web API as an image service and make POST requests on it for uploading photos? What are some pros and cons of this approach? Is using ASP.NET Web API overhead for a service like this?

like image 704
Nebojsa Veron Avatar asked Aug 03 '12 17:08

Nebojsa Veron


Video Answer


2 Answers

ASP.NET Web API works great with async I/O -- it uses the new Task-based async model in .NET 4 (and particular .Net 4.5) which makes it straight forward to build async controllers and coordinate multiple asynchronous operations. If this model is new to you then I would recommend this presentation on channel9.

For uploads, ASP.NET Web API supports completely async MIME multipart file upload based on the common HTML file upload model from a form. You can see an example of this in the FileUploadSample available as source.

It is also straight forward to serve files asynchronously using the StreamContent. Here you (in the controller) open a file, create an HttpResponseMessage and attach an HttpContent in the form of a StreamContent wrapping the file and that's it.

This all happens without blocking any threads on I/O.

Hope this helps,

Henrik

like image 96
Henrik Frystyk Nielsen Avatar answered Sep 28 '22 06:09

Henrik Frystyk Nielsen


It depends on how much concurrency and how many users your application may have.

The nature of this kind of application is I/O centric, meaning that your ASP.NET server will be most of the time waiting for I/O operations to complete. In scenarios with high concurrency, this will cause your ASP.NET managed thread pool to crash with thread starvation.

I would recommend:

1) If you keep the ASP.NET initiative, please, implement the IAsync programming model. This will make your web application more able to scale.

2) If you don't want to deal with IAsyncResult, then put some load balancer in the middle and scale horizontally, adding more servers as you need them. This may incur in the need to re-design your ASP.NET application as as Web Farm, adding a bit of complication (session state management, authentication, authorization, etc).

3) Try a different technology, Node.js is well know for dealing great with I/O high latency, programming models.

like image 28
Adrian Salazar Avatar answered Sep 28 '22 05:09

Adrian Salazar