How much extra overhead is generated when sending a file over a web service as a byte array?

StackOverflow https://stackoverflow.com/questions/11820

  •  08-06-2019
  •  | 
  •  

Question

This question and answer shows how to send a file as a byte array through an XML web service. How much overhead is generated by using this method for file transfer? I assume the data looks something like this:

<?xml version="1.0" encoding="UTF-8" ?>
<bytes>
    <byte>16</byte>
    <byte>28</byte>
    <byte>127</byte>
    ...
</bytes>

If this format is correct, the bytes must first be converted to UTF-8 characters. Each of these characters allocates 8 bytes. Are the bytes stored in base 10, hex, or binary characters? How much larger does the file appear as it is being sent due to the XML data and character encoding? Is compression built into web services?

Was it helpful?

Solution

Typically a byte array is sent as a base64 encoded string, not as individual bytes in tags.

http://en.wikipedia.org/wiki/Base64

The base64 encoded version is about 137% of the size of the original content.

OTHER TIPS

I use this method for some internal corporate webservices, and I haven't noticed any major slow-downs (but that doesn't mean it's not there).

You could probably use any of the numerous network traffic analysis tools to measure the size of the data, and make a judgment call based off that.

I'm not sure about all the details (compressing, encoding, etc) but I usually just use WireShark to analyze the network traffic (while trying various methods) which then allows you to see exactly how it's sent.

For example, if it's compressed the data block of the packet shouldn't be readable as plain text...however if it's uncompressed, you will just see plain old xml text...like you would see with HTTP traffic, or even FTP in certain cases.

To echo what Kevin said, in .net web services if you have a byte array it is sent as a base64 encoded string by default. You can also specify the encoding of the byte array beforehand.

Obviously, once it gets to the server (or client) you need to manually decode the string back into a byte array as this isn't done automagically for you unfortunately.

The main performance hit isn't going to be from the transfer of the encoded file, it's going to be in the processing that the server has to do to encode the file pre-transfer (unless the files don't change often and the encoded version can be cached somehow).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top