Skip to content

Instantly share code, notes, and snippets.

@justinyoo
Created September 8, 2019 14:09
Show Gist options
  • Save justinyoo/6647b4da30201624a6b3eac372c53657 to your computer and use it in GitHub Desktop.
Save justinyoo/6647b4da30201624a6b3eac372c53657 to your computer and use it in GitHub Desktop.
// Sends message
var @object = new MyClass() { Hello = "World" };
var payload = JsonConvert.SerializeObject(@object);
var body = Encoding.UTF8.GetBytes(payload);
var message = new Message(body);
// Receives message
var body = message.Body;
var payload = Encoding.UTF8.GetString(body);
var @object = JsonConvert.DeserializeObject<MyClass>(payload);
// XML Serialiser
var @object = new MyClass() { Hello = "World" };
var serialiser = new DataContractSerializer(typeof(MyClass));
var message = new BrokeredMessage(@object, serialiser);
// JSON Serialiser
var @object = new MyClass() { Hello = "World" };
var serialiser = new DataContractJsonSerializer(typeof(MyClass));
var message = new BrokeredMessage(@object, serialiser);
// Receives message
var payload = message.GetBody<string>(serialiser);
var @object = JsonConvert.DeserializeObject<MyClass>(payload);
// Sends message
var @object = new MyClass() { Hello = "World" };
var payload = JsonConvert.SerializeObject(@object);
var body = Encoding.UTF8.GetBytes(payload);
var stream = new MemoryStream(body);
var message = new BrokeredMessage(stream);
// Receives message
var stream = message.GetBody<Stream>();
var reader = new StreamReader(stream);
var payload = await reader.ReadToEndAsync().ConfigureAwait(false);
var @object = JsonConvert.DeserializeObject<MyClass>(payload);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment