A web service returns base64 encoded data. The goal is to parse it and store
it into binary file with .dat extension. This file is then will be used by a
custom program to produce diagrams. As far as I know base64 data is not any
known graphic format, from what I understand it's just encoded stream of
bytes. Which I need to write to .dat file. Where to start? any links or
suggestions?
Thank you.
Bruce Wood - 02 May 2005 23:30 GMT
Have you tried this?
Declare the element in question in the XML schema for the Web Service
as being "base64Binary".
Load the results of the Web Service call into a DataSet. The resulting
DataColumn should have a type of Byte and the byte array it contains
should be the binary version of the base 64 encoding in the XML.
Failing that, I did write my own base64 encoding class that I could
pass along.
laimis - 02 May 2005 23:34 GMT
If you care just saving the bytes into the file, use FileStream class
provided by .net. It provides a Write method that accepts a byte array
as a parameter (byte array would be your base64 data).
If you need to decode base64 encoded data, simple use
Convert.ToBase64String() method which is also provided by the framework.
base64 is nothing special, just bytes which values are limited by the
set of characters that belong to base64 encoding.
Does that answer your question?
laimis - 02 May 2005 23:36 GMT
If you care just saving the bytes into the file, use FileStream class
provided by .net. It provides a Write method that accepts a byte array
as a parameter (byte array would be your base64 data).
If you need to decode base64 encoded data, simple use
Convert.ToBase64String() method which is also provided by the framework.
base64 is nothing special, just bytes which values are limited by the
set of characters that belong to base64 encoding.
Does that answer your question?
Joshua Flanagan - 03 May 2005 03:40 GMT
As the other posters have hinted at, you just need to use the Convert
class and a way to write the data to disk (FileStream works nicely).
Assuming your base64 data is in a string named receivedBase64string, and
you want to write it to the file c:\received.data
using System.IO;
byte[] rawData = Convert.FromBase64String(receivedBase64string);
using (FileStream fs = new FileStream(
@"c:\received.dat",
FileMode.Create))) {
fs.Write(rawData, 0, rawData.Length);
}
Joshua Flanagan
http://flimflan.com/blog
> A web service returns base64 encoded data. The goal is to parse it and store
> it into binary file with .dat extension. This file is then will be used by a
[quoted text clipped - 4 lines]
>
> Thank you.
LP - 03 May 2005 14:37 GMT
That's easier than I thought, thanks everyone!
> As the other posters have hinted at, you just need to use the Convert
> class and a way to write the data to disk (FileStream works nicely).
[quoted text clipped - 22 lines]
> >
> > Thank you.