Created
September 8, 2019 14:09
-
-
Save justinyoo/6647b4da30201624a6b3eac372c53657 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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