Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a simple question. Should I return a byte-array or simply base64 encode my binary data, when exposing it through a web service in .NET? Is there any pros/cons with either method, which is mostly supported etc.

like image 857
Siewers Avatar asked Mar 26 '10 08:03

Siewers


1 Answers

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.

like image 125
Darin Dimitrov Avatar answered Sep 19 '22 08:09

Darin Dimitrov