Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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
You can’t perform that action at this time.