Question

    [return: System.Xml.Serialization.XmlElementAttribute("return", DataType="base64Binary")]
    public byte[] get(...)

I am trying to get a xml(utf-8) from this webservice. I have tried multiple things to try and get the xml out of the byte array like:

stream
encoding
decoder
converter

[Extra info] When decoding the byte array with Encoding.UTF8.GetString(bytes) I get a string with strange signs and symbols but also with some text Starting with: %PDF-1.4

[SOLUTION] Writing the byte array to a pdf file makes it readable.

Was it helpful?

Solution

I think the web service provides a byte stream that is simply base64-encoded data represented as integers instead of chars. I believe that the base64 chars are a subset of ASCII, so you need to convert the byte array to ASCII (i.e. base64 represented as chars), then convert these chars from base64:

var base64AsAscii = Encoding.ASCII.GetString(bytesFromWebService);
var decodedBytes = Convert.FromBase64String(bytesAsAscii);
var text = Encoding.UTF8.GetString(decodedBytes);

OTHER TIPS

You can try Convert.ToBase64String.

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