/
MessageInteropExtensions.xml
113 lines (104 loc) · 7.12 KB
/
MessageInteropExtensions.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<Type Name="MessageInteropExtensions" FullName="Microsoft.Azure.ServiceBus.InteropExtensions.MessageInteropExtensions">
<TypeSignature Language="C#" Value="public static class MessageInteropExtensions" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi abstract sealed beforefieldinit MessageInteropExtensions extends System.Object" />
<TypeSignature Language="DocId" Value="T:Microsoft.Azure.ServiceBus.InteropExtensions.MessageInteropExtensions" />
<TypeSignature Language="VB.NET" Value="Public Module MessageInteropExtensions" />
<TypeSignature Language="F#" Value="type MessageInteropExtensions = class" />
<AssemblyInfo>
<AssemblyName>Microsoft.Azure.ServiceBus</AssemblyName>
<AssemblyVersion>5.1.3.0</AssemblyVersion>
<AssemblyVersion>5.2.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Object</BaseTypeName>
</Base>
<Interfaces />
<Docs>
<summary>
A Message Extension Class that provides extension methods to deserialize
the body of a message that was serialized and sent to ServiceBus Queue/Topic
using the WindowsAzure.Messaging client library. The WindowsAzure.Messaging
client library serializes objects using the
<see cref="T:Microsoft.Azure.ServiceBus.InteropExtensions.DataContractBinarySerializer" /> (default serializer) or <see cref="T:System.Runtime.Serialization.DataContractSerializer" />
when sending message. This class provides extension methods to deserialize
and retrieve the body of such messages.
</summary>
<remarks>
1. If a message is only being sent and received using this Microsoft.Azure.ServiceBus
client library, then the below extension methods are not relevant and should not be used.
2. If this client library will be used to receive messages that were sent using both
WindowsAzure.Messaging client library and this (Microsoft.Azure.ServiceBus) library,
then the Users need to add a User property <see cref="P:Microsoft.Azure.ServiceBus.Message.UserProperties" />
while sending the message. On receiving the message, this property can be examined to
determine if the message was from WindowsAzure.Messaging client library and if so
use the message.GetBody() extension method to get the actual body associated with the message.
----------------------------------------------
Scenarios to use the GetBody Extension method:
----------------------------------------------
If message was constructed using the WindowsAzure.Messaging client library as follows:
<code>
var message1 = new BrokeredMessage("contoso"); // Sending a plain string
var message2 = new BrokeredMessage(sampleObject); // Sending an actual customer object
var message3 = new BrokeredMessage(Encoding.UTF8.GetBytes("contoso")); // Sending a UTF8 encoded byte array object
await messageSender.SendAsync(message1);
await messageSender.SendAsync(message2);
await messageSender.SendAsync(message3);
</code>
Then retrieve the original objects using this client library as follows:
(By default <see cref="T:Microsoft.Azure.ServiceBus.InteropExtensions.DataContractBinarySerializer" /> will be used to deserialize and retrieve the body.
If a serializer other than that was used, pass in the serializer explicitly.)
<code>
var message1 = await messageReceiver.ReceiveAsync();
var returnedData1 = message1.GetBody<string>();
var message2 = await messageReceiver.ReceiveAsync();
var returnedData2 = message1.GetBody<SampleObject>();
var message3 = await messageReceiver.ReceiveAsync();
var returnedData3Bytes = message1.GetBody<byte[]>();
Console.WriteLine($"Message3 String: {Encoding.UTF8.GetString(returnedData3Bytes)}");
</code>
-------------------------------------------------
Scenarios to NOT use the GetBody Extension method:
-------------------------------------------------
If message was sent using the WindowsAzure.Messaging client library as follows:
var message4 = new BrokeredMessage(new MemoryStream(Encoding.UTF8.GetBytes("contoso")));
await messageSender.SendAsync(message4);
Then retrieve the original objects using this client library as follows:
var message4 = await messageReceiver.ReceiveAsync();
string returned = Encoding.UTF8.GetString(message4.Body); // Since message was sent as Stream, no deserialization required here.
</remarks>
</Docs>
<Members>
<Member MemberName="GetBody<T>">
<MemberSignature Language="C#" Value="public static T GetBody<T> (this Microsoft.Azure.ServiceBus.Message message, System.Runtime.Serialization.XmlObjectSerializer serializer = default);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig !!T GetBody<T>(class Microsoft.Azure.ServiceBus.Message message, class System.Runtime.Serialization.XmlObjectSerializer serializer) cil managed" />
<MemberSignature Language="DocId" Value="M:Microsoft.Azure.ServiceBus.InteropExtensions.MessageInteropExtensions.GetBody``1(Microsoft.Azure.ServiceBus.Message,System.Runtime.Serialization.XmlObjectSerializer)" />
<MemberSignature Language="VB.NET" Value="<Extension()>
Public Function GetBody(Of T) (message As Message, Optional serializer As XmlObjectSerializer = Nothing) As T" />
<MemberSignature Language="F#" Value="static member GetBody : Microsoft.Azure.ServiceBus.Message * System.Runtime.Serialization.XmlObjectSerializer -> 'T" Usage="Microsoft.Azure.ServiceBus.InteropExtensions.MessageInteropExtensions.GetBody (message, serializer)" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.Azure.ServiceBus</AssemblyName>
<AssemblyVersion>5.2.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>T</ReturnType>
</ReturnValue>
<TypeParameters>
<TypeParameter Name="T" />
</TypeParameters>
<Parameters>
<Parameter Name="message" Type="Microsoft.Azure.ServiceBus.Message" RefType="this" />
<Parameter Name="serializer" Type="System.Runtime.Serialization.XmlObjectSerializer" />
</Parameters>
<Docs>
<typeparam name="T">To be added.</typeparam>
<param name="message">To be added.</param>
<param name="serializer">To be added.</param>
<summary>
Deserializes the body of a message that was serialized using XmlObjectSerializer
</summary>
<returns>To be added.</returns>
<remarks>To be added.</remarks>
</Docs>
</Member>
</Members>
</Type>