0

I'm building a Xamarin client that reads messages from the Azure Service Bus.

My REST code can successfully pull a message off the Service Bus, but what I'm getting back appears to be binary (as in non-Text...I know it's all binary ;) )

This is the test code on Windows:

byte[] response = webClient.UploadData(fullAddress, "DELETE", new byte[0]);
MemoryStream ms = new MemoryStream(response);
BrokeredMessage bm = new BrokeredMessage(ms);
responseStr = bm.GetBody<string>();

My problem is on Xamarin/Mono, I don't have a BrokeredMessage.

So my question is how to I de-serialize a BrokeredMessage by hand?

Here's the first few bytes of the response variable looks like:

40 06 73 74 72 69 6e 67 08 33 68 74 74 70 3a 2f 2f 73 63 68

All the examples, I've found, say that I should be getting back XML....it 'almost' looks like XML but the 06 and the 08 are throwing me off.

I'm sure that I'm missing something simple, but I can't find it.

Any guidance would be welcome.

Iunknown
  • 347
  • 1
  • 2
  • 16
  • Did you try to encode byte array into a string using already available libraries? (i.e. `System.Text.Encoding.UTF8.GetString`) – mert Jan 28 '16 at 06:52
  • Yes. The resulting string isn't XML due to the characters like the 06 and the 08. I found somewhere something called BinaryXML, which this might be but can't find anything on how to use it. – Iunknown Jan 28 '16 at 14:37

1 Answers1

0

I figured it out so I'm posting the answer just in case someone else runs into the same problem.

response = webClient.UploadData(fullAddress, "DELETE", new byte[0]);
responseStr = System.Text.Encoding.UTF8.GetString(response);
Dictionary<string, object> result = new Dictionary<string, object>();
foreach (var headerKey in webClient.ResponseHeaders.AllKeys)
  result.Add(headerKey, webClient.ResponseHeaders[headerKey]);

MemoryStream ms = new MemoryStream(response);
DataContractSerializer serializer = new DataContractSerializer(typeof(string));
XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader(ms, XmlDictionaryReaderQuotas.Max);
object deserializedBody = serializer.ReadObject(reader);
responseStr = (string)deserializedBody;
result.Add("body", responseStr);

The BrokeredMessage properties are stored in the ResponseHeaders

Iunknown
  • 347
  • 1
  • 2
  • 16