@@ -157,16 +157,54 @@ Console.WriteLine("Published deposit event!");
157157
158158### Interact with output bindings
159159
160+ When calling ` InvokeBindingAsync ` , you have the option to handle serialization and encoding yourself,
161+ or to have the SDK serialize it to JSON and then encode it to bytes for you.
162+
163+ {{% alert title="Important" color="warning" %}}
164+ Bindings differ in the shape of data they expect, take special note and ensure that the data you
165+ are sending is handled accordingly. If you are authoring both an output and an input, make sure
166+ that they both follow the same conventions for serialization.
167+ {{% /alert %}}
168+
169+ #### Manual serialization
170+
171+ For most scenarios, you're advised to use this overload of ` InvokeBindingAsync ` as it gives you clarity and control over
172+ how the data is being handled.
173+
174+ _ In this example, the data is sent as the UTF-8 byte representation of the string._
175+
176+ ``` csharp
177+ using var client = new DaprClientBuilder ().Build ();
178+
179+ var request = new BindingRequest (" send-email" , " create" )
180+ {
181+ // note: This is an example payload for the Twilio SendGrid binding
182+ Data = Encoding .UTF8 .GetBytes (" <h1>Testing Dapr Bindings</h1>This is a test.<br>Bye!" ),
183+ Metadata =
184+ {
185+ {
" emailTo" ,
" [email protected] " },
186+ { " subject" , " An email from Dapr SendGrid binding" },
187+ },
188+ }
189+ await client .InvokeBindingAsync (request );
190+ ```
191+
192+ #### Automatic serialzation and encoding
193+
194+ _ In this example, the data is sent as a UTF-8 encoded byte representation of the value serialized to JSON._
195+
160196``` csharp
161- // Example payload for the Twilio SendGrid binding
197+ using var client = new DaprClientBuilder ().Build ();
198+
162199var email = new
163200{
201+ // note: This is an example payload for the Twilio SendGrid binding
202+ data = " <h1>Testing Dapr Bindings</h1>This is a test.<br>Bye!" ,
164203 metadata = new
165204 {
166205167206 subject = " An email from Dapr SendGrid binding" ,
168- },
169- data = " <h1>Testing Dapr Bindings</h1>This is a test.<br>Bye!" ,
207+ },
170208};
171209await client .InvokeBindingAsync (" send-email" , " create" , email );
172210```
0 commit comments