Should I use Base64 encoding or byte[] for returning binary data in .NET web service?

Use byte array. Over a SOAP protocol this byte array will automatically be serialized using base64 encoding. Your web service will be also more descriptive if you use a byte array.

Imagine someone who wants to consume your web service and looking at a method whose signature looks like this: string GetBinaryImageFromDatabase() He might wonder why does this method returns a string and what am I going to do with this string, while if it returns a byte array it is much more clear I've seen web service method that look like this: string SaveCustomer(string customer) Guess what the customer and the return types were: they were some proprietary XML. There's absolutely no sense of using SOAP if people reinvent protocols over it.

Use byte array. Over a SOAP protocol this byte array will automatically be serialized using base64 encoding. Your web service will be also more descriptive if you use a byte array.

Imagine someone who wants to consume your web service and looking at a method whose signature looks like this: string GetBinaryImageFromDatabase(); He might wonder why does this method returns a string and what am I going to do with this string, while if it returns a byte array it is much more clear. I've seen web service method that look like this: string SaveCustomer(string customer); Guess what the customer and the return types were: they were some proprietary XML. There's absolutely no sense of using SOAP if people reinvent protocols over it.

Interesting points. I'll discuss this with the other members of my team, to see if they have any objections :) – TigerShark Mar 26 '10 at 10:16.

One consideration is that a Base64 encoded string enables you to use the "Test Form" to help debug any issues, etc. The Byte array is a complex type and therefore the test form will not work.

But the content of the encoded string still would be a byte array. If I need to debug, I could always call Convert. ToBase64String(byte inArray).

– TigerShark Mar 26 '10 at 10:15 Yes, my point is purely that in order to call/test your method you will need to build a test harness that passes/receives a byte array. If you use a base64 string then you can call your webmethod manually without writing a test harness. – Robin Day Mar 26 '10 at 10:49.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions