0
    [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.

2 Answers 2

1

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);
Sign up to request clarification or add additional context in comments.

12 Comments

Thank you for your response. I tried it, but i got following error. The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.
This is the response after the get string. %PDF-1.4 %???? 5 0 obj <</Type/XObject/ColorSpace/DeviceGray/Subtype/Image/BitsPerComponent 8/Width 319/Length 96/Height 238/Filter/FlateDecode>>stream x???1
@Kenny - My code includes 2 calls to GetString: which one? Anyway it looks like the base64 data encodes PDF content, not simple text.
The first get string gives that response.
@Kenny - I'm trying to understand this weird name base64Binary. You say the XML is UTF8 so might be worthwhile trying UTF8 for both calls to GetString?
|
1

You can try Convert.ToBase64String.

1 Comment

No, it does not work. I tried the convert methods. Is there anyway to know which decoding i need to do? I just need to get my data from the byte array

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.