Hihi all,
I would need to create a restful json wcf webservice method with .NET and c#, this webservice method will take in a couple of information to perfome some checking and validation. Once the validation is completed, it will access the protected azure blob storage to grab a file and return the stream of the file b开发者_如何学Pythonack through the webservice.
And now I have an iphone app to consume the webservice for downloading a file, but the filesize could be big enough that the download process might be interrupted before completion. What should be the best way to handle the resume download mechanism?
What I have in mind is:
- webservice receive the request with the file byte range as part of the parameter. Perform the required validation.
- read the file from the blob storage based on the byte range parameters and store it as a temporary file into my disk storage.
- return the bytes of the file in stream through the webservice.
- delete the temporary file.
Is this a good way of doing it? How can I depend on the Range Header for my scenario, where my file is not a static file residing at a fixed location in the server?
Thanks in advance! :)
Avoid WCF completely. Use ASP.NET Generic handler for this and HTTP Chunked encoding with HTTP Range header for requesting specific part of data stream. That is exactly mechanism proposed by HTTP standard for this scenario and Generic handler is the simplest way to achieve that. WCF will bring only a lot of unneeded stuff around and make this much more complex.
If you are serving dynamic files using ASP.NET WebForms you could look at implementing a custom Http Handler, like the one described in this article by DotNetSlackers.
If you are serving dynamic files using ASP.NET MVC then you could use Lib.Web.Mvc, a library which contains a custom set of ActionResults which respond to range requests. I am using them myself and have had no problems with them at all.
If you are serving static files via ASP.NET Webforms OR MVC then I would recommend looking at Talifun-Web which provides a nice set of Http Modules and Handlers to effectively and efficiently serve files.
精彩评论