views:

67

answers:

4

Hi,

what is the best way to transfer an 800*600 image via a webservice using C#?

I am looking for a fast method.

thanks

A: 

If you want to save bandwidth/Speed (Not tested on many different image formats)

7zip C# SDK (http://www.7-zip.org/sdk.html) 7-Zip the bytes and send the bytes

and where needed un"7-Zip" (LZMA) the bytes and convert to image.

Chris Schroeder
+1  A: 

If you are using WCF 4.0 then you could use socket programming and from there you could transmit as binary (compressed with 7zip of course).

If the image is already in a compressed format (jpeg for example) then compression would not be that great and it would slow down the actual total transfer (compress - transmit - decompress).

Stecy
This might be a good idea (I'm not familiar with doing this) if it's an acceptable solution, but then it technically wouldn't be a web service.
Dr. Wily's Apprentice
A: 

You'll probably want to send the image in small pieces (even if it's zipped up as Chris Schroeder mentioned), say 50K at a time. This gives you two advantages over sending the entire file at once:

  • You can show progress to the user
  • If one piece fails to transmit then you only have to send that piece rather than the whole file

However, with this method is you now have 2 new problems to handle and that is making sure you get ALL of the pieces, and that they're in the correct order.

Sending some metadata with the image data can fix this situation. An identifier that relates this piece of data with the others, and the piece number which will determine where this piece should be in relation to the rest of the pieces.

Jacob Ewald
a bit redundent as this is done automaticly by the network on several layers. In practice I wouldn't be surprised if this acutally slowed down the transfer.
WalterJ89
In practice, networks fail. You can easily recover from that and still retain your spot in the transfer. The goal here is a better user experience. The user stays informed of progress and the program can easily recover from a network problem. Being able to resume a transfer is, in my opinion, much higher in priority than the overhead involved with the redundancy in sending portions of the file.
Jacob Ewald
+1  A: 

If you're using WSE, consider using MTOM.

If you're using WCF, you could use an MTOM binding.

Dr. Wily's Apprentice