REST service and big files - c#

Can REST web service (which usually produces e.g. simple JSONs) both handle and return big binary input/output data?
I mean, to call a REST service by a HTTP POST providing big file and afterwards reading the big result back? Is REST ok for that? ("Big" = few megabytes)

With text serializers such as JSON and XML you would get about 33% increase of the size of the files over the wire as the binary data needs to be Base64 encoded. There are more optimized protocols such as MTOM to handle this scenario. WCF supports MTOM out of the box.

REST architectures are quite capable of using HTTP to serve up application/octet-stream, which is just a stream of bytes. HTTP can quite reliably serve very large files.

Since REST is primarily a service over HTTP, standard advantages and limitations of HTTP apply to REST services too. You can send large files of few MBs as POST to REST API in a way similar that one uploads a large file to a web app.

Related

Using web service to send large object (ex. image bitmap)

I'm trying to use WCF web service in C# to send the bitmap data of an image to the client, I plan to send this as an object. I want to understand the nature of web service.
My question is how does this work with a large file? such as 10MB? Does web service work in one single request/response to send all 10MB worth of bitmap data? What if a network error occurs? will the client have to reissue the request?
The reason I ask this is I have been working with Socket and often when it comes to large file, I break it down to trunk of manageable size (such as 4kb) and then send it, if one succeed then I'm sending the next 4kb until all the data are transferred.
Thanks again.
The same principle can be applied here. You can send it in chunks. Related post you might find usefull - wcf upload/download large files (i.e. Img, mp3) in chunks with windows service

Download very large files (8GB+) - combining WCF and WebClient?

I have quite some trouble creating a WCF service that supports downloads of very large files. I have read a lot of guides on how to set transferMode attribute to Streamed, increase all messageSize and bufferSize attributes to Int32.MaxValue, and still I have no luck. (I am also returning the stream as the message body via the MessageBodyMember attribute, and metadata is sent via the headers using the MessageHeader attributes).
If I set all these attributes, I can download smaller files fine, but when I try to download 1-2GB files I simply get a 400 bad request error which makes it rather hard to debug...
My service should ideally support file sizes of at least 8GB. Is this even doable with WCF? The various messageSize attributes of the web.config file seem to be limited to Int32.MaxValue which equals a maximum file size of 2GB.
From my studies I have found that it seems I will have to use WebClient.DownloadFile instead.
Files should only be available for download to users who have the required rights. With WCF my download method could take a token-parameter that the server could check and return the stream only if the user had rights to download the requested file. This does not seem straight forward using the WebClient approach. If anyone has some guidelines on how to do this (via the WebClient), I would very much appreciate it.
Ideally my WCF service should administer and provide user tokens and somehow bind to every individual file what tokens are currently legal (tokens should be usable only once). Download should then happen via the WebClient.
Thanks in advance for any clues.
You can do this in WCF. Many moons ago I built a service that did this (we didn't have a web server as part of our configuration). We used WCF streaming:
http://msdn.microsoft.com/en-us/library/ms733742.aspx
The strategy to deal with large payloads is streaming. While messages,
especially those expressed in XML, are commonly thought of as being
relatively compact data packages, a message might be multiple
gigabytes in size and resemble a continuous data stream more than a
data package. When data is transferred in streaming mode instead of
buffered mode, the sender makes the contents of the message body
available to the recipient in the form of a stream and the message
infrastructure continuously forwards the data from sender to receiver
as it becomes available.

WCF Webservice and Silverlight with compression

My application consists of a WCF web service and a silverlight client. I need to transfer data on the order of GBs. Is it possible to send compressed data so that it can be uncompressed by the client when it is received? What classes can I make use for this?
I never had to use it but maybe you should take a look at SharpZipLib (An open source dll for compression)
Here's also 3 links about WCF compression:
http://bloggingabout.net/blogs/ramon/archive/2008/11/06/wcf-and-http-gzip-deflate-compression-and-silverlight.aspx
http://weblogs.asp.net/cibrax/archive/2006/03/29/441398.aspx
http://frenk.wordpress.com/2009/11/08/gzip-compression-between-wcf-web-service-and-silverlight/

Output large dataset from web service

I wonder if anyone experienced with returning large dataset from webservice.
The dataset is around 10,000 x 60 floats.
I will be using http wcf for my webservice.
Any ideas to approach it are welcome :)
Thanks.
There's no technical reason you can't do it.
You just have to consider the amount of data that is being transfered and realize that it may take your client a while to download and deserialize the results.
If you're really worried about the amount of data going over the wire, you could use a library like Google's protocol buffers to do binary serialization (rather than the XML or JSON that you get out of the box with WCF). You can find the .NET port of Protocol Buffers at:
protobuf-net - Project Hosting on Google Code
This is not big data set. You can use web service to return such dataset without any implementation problems. You just need to set maxReceivedMessageSize and maxArrayLength on the client.
The real set of questions you should ask is:
How many concurrent clients can use this service?
What is expected response time?
How often does a client call this service?
What bandwidth is available on production server?
What bandwidth is available on clients?
Answers to these questions show you if 2.3MB is a big data set. If you are affraid of performance and response time you should definitely plan load tests.

Soap Server Images

What the best way of passing images over a soap server?
I'm using WCF 4.0 and flex for my front end.
I cannot say if this is the best, but I have used Base64 encoding to send binary data as XML within SOAP as well as AMQP. Worked well for what I needed, but YMMV.

Categories

Resources